Hi I'm trying to ensure that every request has a c...
# ktor
t
Hi I'm trying to ensure that every request has a cookie before the request gets to my routes (and initialise a new one if one doesn't exist already). I'm coming from NodeJS/Express so I'm looking the the middleware equivalent. Do I need to write a custom feature for this or is there an easier way to intercept the request and add the cookie if its not there already? In addition to this I'd like to have a authOnly high order function to deny access to certain routes ... i suppose i could do something like
get("/path") = authOnly { ... }
? but figured there's a common approach to solving these?
Ahh the authentication feature allows for the 'onlyAuth' equivalent ... might be able to get this to work
okay solved! Extended route and then added an interceptor (simplified code):
Copy code
fun Route.authOnly() {
  val route = createChild(selector)

  route.intercept ... {
     // my logic
  }

  return route.build()
}