any better way to require a session to be present ...
# ktor
a
any better way to require a session to be present than this?
Copy code
get("/") { _ ->
    val session = call.sessions.get<DashSession>() ?: return@get call.respondRedirect("/login")
    /* code */
}
📝 1
1
d
You can use status pages as suggested by @Nikky I have created a sample using it:
Copy code
inline fun <reified T> CurrentSession.getOrThrow(): T =
    this.get<T>() ?: throw SessionNotFoundException(T::class)
https://github.com/ktorio/ktor-samples/blob/379b2e83146ed6ca9ad42bcc77bc2f346508bd1a/other/redirect-with-exception/src/RedirectWithExceptionApplication.kt