How do I group routes? I want to apply an `authent...
# ktor
r
How do I group routes? I want to apply an
authentication
block to a bunch of routes but they're not all under a parent path of all authenticated routes
d
What about
route
? https://ktor.io/features/routing.html#path Something like:
Copy code
route("/") {
  install(auth) {}

  get("/full/route1") {}
  get("/other/route2") {}
}
(untested)
But maybe something like
group { ... }
would be more obvious
o
This is being refactored for exactly this inconvenience
d
btw, any news about such api?
Copy code
authenticate {
 // routes with auth rules applied
}
can't find a ticket in the repo. i believe it was there
a
I think a ticket would be nice to keep track of the status.
o
I think it is hidden somewhere in openapi (swagger) discussion
It’s in a local branch already working, so no need to create a ticket. Next week will hopefully be in master. But it’s a breaking API change without any sane way to build a migration path…
metal 1
d
@ribesg Maybe something like this could help:
Copy code
val commonConfig : Route.() -> Unit = {
        install(auth) {}
        ...
}

route("/route1") {
  apply(commonConfig)
}

route("/route2") {
  apply(commonConfig)
}
r
@Deactivated User this does not work as this applies the authentication block to absolutely all routes (as all routes are under /)
d
Makes sense. Ilya is going to cover it soon. In the meantime you can extract the auth code to a function and apply it manually to each route.
r
That's the only solution I have I guess. In my context it's not a problem, but let's say I have hundreds of routes, would that create a lot of objects?
d
I suppose those objects will be created per route and not per call, so shouldn’t be an issue. You might have dozens or even hundreds of routes but still a limited number and created at the beginning so will go to the old generation. Still this approach forces you to write more code. But it seems that it is going to be covered soon.
o
@ribesg you might want to check
auth-dsl
branch to see if it works for you