Route.resource(): how to exclude a route from the auth middleware?


I have this: => {
  Route.resource('users', 'UserController').apiOnly()

How can I exclude Route.get('api/v1/users', 'UserController.index') to be under the controller of the authentication middleware? Would adding the following be Ok ?

Route.get('api/v1/users', 'UserController.index').middleware['guest']


I doubt it will work because you have assigned the named middleware “auth” to the larger group.


I read in the documentation:

Group middleware executes before route middleware.

So I think there is not a solution to it, unless if I split the group and declare the routes one by one. Not sure. Will see if the authors would say something on this. Thank you


Why not try simply by moving the explicit route you want to exclude above the Route group? and not have any middleware or guest to it.


Route.resource() will generate it, so it will be affected by that middleware. @devanandb


Do not use Route.resource and put each route where you want.


Suppose I am lazy to write a lot, do you know any shorter way to achieve this? @jorgeyoma


Hey all! :wave:

There’s multiple way to do so.

  1. The route file is read from top to bottom and will stop when a matching route has been found. Therefore, you can simply put your route in top of the
  2. You can use the except() function to remove some routes from the resource.