mirror of
https://github.com/SOR2171/Springboot4-Vue3_Demo.git
synced 2026-10-23 11:31:10 +08:00
fix: relogin
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
package com.github.sor2171.backend.entity.vo.response
|
package com.github.sor2171.backend.entity.vo.response
|
||||||
|
|
||||||
|
import com.github.sor2171.backend.utils.DateUtils.getCurrentDateTime
|
||||||
|
import kotlinx.datetime.LocalDateTime
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class ReloginVO(
|
data class ReloginVO(
|
||||||
val token: String = "",
|
val token: String = "",
|
||||||
val expire: String = "",
|
val expire: LocalDateTime = getCurrentDateTime(),
|
||||||
)
|
)
|
||||||
+2
-1
@@ -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.entity.vo.response.ReloginVO
|
||||||
import com.github.sor2171.backend.service.AccountService
|
import com.github.sor2171.backend.service.AccountService
|
||||||
import com.github.sor2171.backend.utils.Const
|
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.DateUtils.getCurrentDateTime
|
||||||
import com.github.sor2171.backend.utils.FlowUtils
|
import com.github.sor2171.backend.utils.FlowUtils
|
||||||
import com.github.sor2171.backend.utils.JwtUtils
|
import com.github.sor2171.backend.utils.JwtUtils
|
||||||
@@ -120,7 +121,7 @@ class AuthorizationService(
|
|||||||
val voMono = accountMono.map {
|
val voMono = accountMono.map {
|
||||||
ReloginVO(
|
ReloginVO(
|
||||||
jwtUtils.createJwt(user, it.id!!, it.username),
|
jwtUtils.createJwt(user, it.id!!, it.username),
|
||||||
jwtUtils.expiresTime().toInstant().toString()
|
DateUtils.dateToLocalDateTime(jwtUtils.expiresTime())
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return voMono
|
return voMono
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
export interface JwtAuth {
|
export interface JwtAuth {
|
||||||
token: string;
|
token: string;
|
||||||
expire: number;
|
expire: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApiResponse<T = any> {
|
export interface ApiResponse<T = any> {
|
||||||
@@ -11,7 +11,7 @@ export interface ApiResponse<T = any> {
|
|||||||
|
|
||||||
export interface LoginResponse {
|
export interface LoginResponse {
|
||||||
token: string;
|
token: string;
|
||||||
expire: number;
|
expire: string;
|
||||||
username: string;
|
username: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ function takeAccessToken(): string | null {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const authObject: JwtAuth = JSON.parse(str);
|
const authObject: JwtAuth = JSON.parse(str);
|
||||||
if (authObject.expire < Date.now()) {
|
if (new Date(authObject.expire).getTime() < Date.now()) {
|
||||||
deleteAccessToken();
|
deleteAccessToken();
|
||||||
ElMessage.warning('Your session has expired, please log in again.');
|
ElMessage.warning('Your session has expired, please log in again.');
|
||||||
return null;
|
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 = {
|
const authObject: JwtAuth = {
|
||||||
token: token,
|
token: token,
|
||||||
expire: expire
|
expire: expire
|
||||||
|
|||||||
Reference in New Issue
Block a user