another option: you might be able to extract that ...
# ktor
o
another option: you might be able to extract that to an extension method on
ApplicationCall
and use that:
Copy code
fun ApplicationCall.requireSession(): DashSession? {
  val session = sessions.get<DashSession>()
  if (session == null) respondRedirect("/login")
  return session
}
use it like this:
Copy code
val session = call.requireSession() ?: return@get
d
The only problem with that approach is that the respondRedirect doesn’t breaks the flow, so you still have to return the function later, and it is more error prone. I have created a sample using
StatusPages
and exceptions here: https://github.com/ktorio/ktor-samples/blob/379b2e83146ed6ca9ad42bcc77bc2f346508bd1a/other/redirect-with-exception/src/RedirectWithExceptionApplication.kt