From 07f0d622d03441ffcaddbb2b9f86fb060ac908de Mon Sep 17 00:00:00 2001 From: TheSaminator Date: Sun, 22 May 2022 14:23:40 -0400 Subject: [PATCH] Attempt to fix 404s for all static content --- src/jvmMain/kotlin/starshipfights/auth/utils.kt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/jvmMain/kotlin/starshipfights/auth/utils.kt b/src/jvmMain/kotlin/starshipfights/auth/utils.kt index 8f18d42..68c4883 100644 --- a/src/jvmMain/kotlin/starshipfights/auth/utils.kt +++ b/src/jvmMain/kotlin/starshipfights/auth/utils.kt @@ -22,9 +22,9 @@ suspend fun Id.resolve(userAgent: String) = UserSession.get(this)?. fun newExpiration(): Instant = Instant.now().plus(2, ChronoUnit.HOURS) -suspend fun UserSession.renewed(clientAddress: String) = copy( +suspend fun UserSession.renewed(clientAddress: String, userData: User) = copy( expiration = newExpiration(), - clientAddresses = if (User.get(user)?.logIpAddresses != true) + clientAddresses = if (!userData.logIpAddresses) emptyList() else if (clientAddresses.lastOrNull() != clientAddress) clientAddresses + clientAddress @@ -42,11 +42,10 @@ suspend fun ApplicationCall.getUserSession() = getUserAndSession().first suspend fun ApplicationCall.getUser() = getUserAndSession().second -suspend fun ApplicationCall.getUserAndSession() = request.pipeline.attributes.getOrNull(UserAndSessionAttribute) +suspend fun ApplicationCall.getUserAndSession() = attributes.getOrNull(UserAndSessionAttribute) ?: request.userAgent()?.let { sessions.get>()?.resolve(it) } - ?.renewed(request.origin.remoteHost) - ?.let { it to User.get(it.user)?.updated() } - ?.also { request.pipeline.attributes.put(UserAndSessionAttribute, it) } + ?.let { sess -> User.get(sess.user)?.let { user -> sess.renewed(request.origin.remoteHost, user) to user.updated() } } + ?.also { attributes.put(UserAndSessionAttribute, it) } ?: (null to null) object UserSessionIdSerializer : SessionSerializer> { -- 2.25.1