修复AccessToken、RefreshToken均可更新Token的问题

This commit is contained in:
BBIT-Kai
2025-12-29 16:28:10 +08:00
parent e6a9a09492
commit e1fcc64236
@@ -76,7 +76,7 @@ fun Application.User(config: AppConfig) {
} else {
// 账号密码不匹配
BaseResponse(status = false, message = "账号密码不匹配,请重新登录", data = null)
}
}
} else {
BaseResponse(status = false, message = "账号已被禁用,请联系管理员", data = null)
}
@@ -149,15 +149,16 @@ fun Application.User(config: AppConfig) {
message = "拿什么乱七八糟的东西跟我换Access Token呢,???",
data = null
)
}
val userId = UUID.fromString(decodedJWT.getClaim("user_id").asString())
// 生成新的access token和refresh token
BaseResponse(
status = true, data = RefreshTokenResponse(
generateAccessToken(config, userId),
generateRefreshToken(config, userId)
} else {
val userId = UUID.fromString(decodedJWT.getClaim("user_id").asString())
// 生成新的access token和refresh token
BaseResponse(
status = true, data = RefreshTokenResponse(
generateAccessToken(config, userId),
generateRefreshToken(config, userId)
)
)
)
}
} catch (ex: Exception) {
BaseResponse(status = false, message = "token解析错误", data = null)
}
@@ -166,16 +167,12 @@ fun Application.User(config: AppConfig) {
authenticate {
get("/getUserInfo") {
val userId = getUserIdByToken(call)
if (userId != null) {
val userInfo = UserDAO.getUserInfoByUserId(userId)
if (userInfo != null) {
val response = BaseResponse(data = userInfo)
call.respond(response)
} else {
call.respond(BaseResponse(data = "查无此人"))
}
val userInfo = UserDAO.getUserInfoByUserId(userId)
if (userInfo != null) {
val response = BaseResponse(data = userInfo)
call.respond(response)
} else {
call.respond(BaseResponse(data = "Token出错"))
call.respond(BaseResponse(data = "查无此人"))
}
}
}