diff --git a/backend/src/main/kotlin/com/github/sor2171/backend/entity/vo/response/ReloginVO.kt b/backend/src/main/kotlin/com/github/sor2171/backend/entity/vo/response/ReloginVO.kt index afcda8e..aa9959c 100644 --- a/backend/src/main/kotlin/com/github/sor2171/backend/entity/vo/response/ReloginVO.kt +++ b/backend/src/main/kotlin/com/github/sor2171/backend/entity/vo/response/ReloginVO.kt @@ -1,9 +1,11 @@ package com.github.sor2171.backend.entity.vo.response +import com.github.sor2171.backend.utils.DateUtils.getCurrentDateTime +import kotlinx.datetime.LocalDateTime import kotlinx.serialization.Serializable @Serializable data class ReloginVO( val token: String = "", - val expire: String = "", + val expire: LocalDateTime = getCurrentDateTime(), ) \ No newline at end of file diff --git a/backend/src/main/kotlin/com/github/sor2171/backend/service/v1/AuthorizationService.kt b/backend/src/main/kotlin/com/github/sor2171/backend/service/v1/AuthorizationService.kt index fcc9e7b..996b47b 100644 --- a/backend/src/main/kotlin/com/github/sor2171/backend/service/v1/AuthorizationService.kt +++ b/backend/src/main/kotlin/com/github/sor2171/backend/service/v1/AuthorizationService.kt @@ -8,6 +8,7 @@ import com.github.sor2171.backend.entity.vo.request.PasswordResetVO import com.github.sor2171.backend.entity.vo.response.ReloginVO import com.github.sor2171.backend.service.AccountService import com.github.sor2171.backend.utils.Const +import com.github.sor2171.backend.utils.DateUtils import com.github.sor2171.backend.utils.DateUtils.getCurrentDateTime import com.github.sor2171.backend.utils.FlowUtils import com.github.sor2171.backend.utils.JwtUtils @@ -120,7 +121,7 @@ class AuthorizationService( val voMono = accountMono.map { ReloginVO( jwtUtils.createJwt(user, it.id!!, it.username), - jwtUtils.expiresTime().toInstant().toString() + DateUtils.dateToLocalDateTime(jwtUtils.expiresTime()) ) } return voMono diff --git a/frontend/src/interfaces/ApiTypes.ts b/frontend/src/interfaces/ApiTypes.ts index 77db25b..3488c80 100644 --- a/frontend/src/interfaces/ApiTypes.ts +++ b/frontend/src/interfaces/ApiTypes.ts @@ -1,6 +1,6 @@ export interface JwtAuth { token: string; - expire: number; + expire: string; } export interface ApiResponse { @@ -11,7 +11,7 @@ export interface ApiResponse { export interface LoginResponse { token: string; - expire: number; + expire: string; username: string; } diff --git a/frontend/src/utils/JwtUtils.ts b/frontend/src/utils/JwtUtils.ts index 1d959b7..d413866 100644 --- a/frontend/src/utils/JwtUtils.ts +++ b/frontend/src/utils/JwtUtils.ts @@ -10,7 +10,7 @@ function takeAccessToken(): string | null { try { const authObject: JwtAuth = JSON.parse(str); - if (authObject.expire < Date.now()) { + if (new Date(authObject.expire).getTime() < Date.now()) { deleteAccessToken(); ElMessage.warning('Your session has expired, please log in again.'); return null; @@ -22,7 +22,7 @@ function takeAccessToken(): string | null { } } -function storeAccessToken(token: string, remember: boolean, expire: number): void { +function storeAccessToken(token: string, remember: boolean, expire: string): void { const authObject: JwtAuth = { token: token, expire: expire