I am using ktor sessions. ```install(Sessions) { ...
# ktor
y
I am using ktor sessions.
Copy code
install(Sessions) {
        val secretEncryptKey = hex("00112233445566778899aabbccddeeff")
        val secretSignKey = hex("6819b57a326945c1968f45236589")
        cookie<UserPrincipal>("_usr", storage = SessionStorageMemory()) {
            cookie.path = "/"
            cookie.maxAgeInSeconds = sessionMaxAge
            cookie.extensions["SameSite"] = "lax"
            cookie.extensions["SameSite"] = "strict"
            transform(SessionTransportTransformerEncrypt(secretEncryptKey, secretSignKey))
        }
    }
    install(Authentication) {
        session<UserPrincipal>("user") {
            challenge { call.respond(HttpStatusCode.Unauthorized, "Unauthorized") }
            validate { session: UserPrincipal ->
                databaseProvider.dbQuery {
                    userApi.getUserById(session.id.toString())?.let { it } ?: run { null }
                }
            }
        }
    }
val ApplicationCall.user
    get() = authentication.principal<UserPrincipal>()!!