refactor: better jwt convert

This commit is contained in:
server_main
2026-08-17 13:00:01 +00:00
parent 0af6fd35ab
commit 3c280c5353
@@ -25,7 +25,7 @@ class JwtUtils(
private val algorithm: Algorithm = Algorithm.HMAC256(key)
private val jwtVerifier: JWTVerifier = JWT.require(algorithm).build()
private val logger = LoggerFactory.getLogger(this::class.java)
fun invalidateJwt(headerToken: String?): Boolean {
val token = this.convertToToken(headerToken) ?: return false
try {
@@ -58,10 +58,10 @@ class JwtUtils(
val decodedJWT = jwtVerifier.verify(token)
if (this.isInvalidToken(decodedJWT.id)) return null
val expiresAt = decodedJWT.expiresAt
return if (Date().after(expiresAt)) null
else decodedJWT
} catch (e: Exception) {
logger.error("Error occurred while resolving JWT", e)
return null
@@ -103,6 +103,8 @@ class JwtUtils(
return cal.time
}
fun convertToToken(headerToken: String?): String? =
headerToken?.replace("Bearer ", "")
fun convertToToken(headerToken: String?): String? {
val token = headerToken?.replace("Bearer ", "")?.trim()
return token?.takeIf { it.isNotEmpty() }
}
}