Fixed current user data

This commit is contained in:
nise.moe 2024-03-09 15:27:04 +01:00
parent 482079fb8f
commit cc3fe8ae96

View File

@ -35,6 +35,14 @@ class AuthService(
return !(authentication == null || authentication is AnonymousAuthenticationToken || authentication.principal == null)
}
fun parseJoinDate(joinDate: String?): OffsetDateTime? {
return try {
if(joinDate == null) null else OffsetDateTime.parse(joinDate)
} catch (e: Exception) {
null
}
}
fun getCurrentUser(): UserInfo {
if(!this.isLoggedIn())
throw IllegalStateException("User is not logged in")
@ -45,8 +53,8 @@ class AuthService(
return UserInfo(
userId = (userDetails.attributes["id"] as Int).toLong(),
username = userDetails.attributes["username"] as String,
country = userDetails.attributes["countryCode"] as String?,
joinDate = OffsetDateTime.parse(userDetails.attributes["joinDate"] as String)
country = userDetails.attributes["country_code"] as String?,
joinDate = parseJoinDate(userDetails.attributes["join_date"] as String?)
)
}