diff --git a/src/main/java/icu/samnyan/aqua/net/components/JWT.kt b/src/main/java/icu/samnyan/aqua/net/components/JWT.kt index c1c0e74f..415c23c2 100644 --- a/src/main/java/icu/samnyan/aqua/net/components/JWT.kt +++ b/src/main/java/icu/samnyan/aqua/net/components/JWT.kt @@ -1,6 +1,7 @@ package icu.samnyan.aqua.net.components import ext.Str +import ext.minus import icu.samnyan.aqua.net.db.AquaNetUser import icu.samnyan.aqua.net.db.AquaNetUserRepo import io.jsonwebtoken.JwtParser @@ -63,6 +64,12 @@ class JWT( .signWith(key) .compact() - fun parse(token: Str): AquaNetUser? = + fun parse(token: Str): AquaNetUser? = try { userRepo.findByAuId(parser.parseSignedClaims(token).payload.subject.toLong()) -} + } catch (e: Exception) { + log.debug("Failed to parse JWT", e) + null + } + + fun auth(token: Str) = parse(token) ?: (400 - "Invalid token") +} \ No newline at end of file