https://kotlinlang.org logo
#ktor
Title
# ktor
j

Jason Han

02/25/2022, 7:16 AM
Hi all, I'm hoping there's a way to do this, but is there any way to authenticate all routes in an application without wrapping authenticate everywhere? We have an application that's structuring the routes
Copy code
routing {
  someRoute1()
  someRoute2()
  ...
  someRoute100()
}
with each group of routes in it's own file
Copy code
fun Application.someRoute1() {
  routing {
    route('/some/{place}') {
      head {
      }
      get {
      }
    }
  }
}
however, we now want to add authentication to all routes, but if we add the authenticate function to the first example,
Copy code
routing {
  authenticate {
    someRoute1()
    someRoute2()
    ...
    someRoute100()
  }
}
it doesn't seem like the individual route functions get the authenticate function. Is there a way to do this without manually editing each individual route file?
i

ishitatsuyuki

02/25/2022, 7:43 AM
Try
Route.routesFoo
and removing
routing {}
from the individual functions
j

Jason Han

02/25/2022, 7:49 AM
ok i think that's good enough, thank you!
a shame that we still need to edit all the route files though
h

Hiranyey Gajbhiye

03/03/2022, 3:11 AM
This was the exact problem i was facing Thanks alot 😁