Describe the feature
Is there a plan for the addition of route guards to the Nitro API framework?
I think this could be done in a similar manner to vue-class-component's custom decorators. It would be really cool to add a @Auth or @Auth({role: "Admin"}) above a defineEventHandler() to take care of the permissions for a handler.
I am transitioning a Nuxt 2 app with an Express API to Nuxt 3, and have noticed that the Nuxt 3 docs do not have examples of authentication, that is the Nitro File Based API docs has no authentication strategies, patterns, or reference to an authentication module that one could use.
I see some libraries like @nuxt-alt/auth have been adapted, but they are not official, and nor do they support basic auth.
My previous Nuxt 2 app used custom JWT auth. It is a requirement. It appears that the current naive solution is as follows:
- Create a login endpoint that gives user a JWT.
- Add a server middleware handler
server/middleware/myAuthHandler.ts that checks the JWT and sets an appropriate prop on the event
- Given that the server middleware according to the docs cannot cut the request short when auth fails, literally add to each file-based endpoint's 'eventHandler' that requires auth, a check on the
event (I mean the whole one file per endpoint is tedious enough).
Additional information
Final checks
Describe the feature
Is there a plan for the addition of route guards to the Nitro API framework?
I think this could be done in a similar manner to
vue-class-component's custom decorators. It would be really cool to add a@Author@Auth({role: "Admin"})above adefineEventHandler()to take care of the permissions for a handler.I am transitioning a Nuxt 2 app with an Express API to Nuxt 3, and have noticed that the Nuxt 3 docs do not have examples of authentication, that is the Nitro File Based API docs has no authentication strategies, patterns, or reference to an authentication module that one could use.
I see some libraries like @nuxt-alt/auth have been adapted, but they are not official, and nor do they support basic auth.
My previous Nuxt 2 app used custom JWT auth. It is a requirement. It appears that the current naive solution is as follows:
server/middleware/myAuthHandler.tsthat checks the JWT and sets an appropriate prop on theeventevent(I mean the whole one file per endpoint is tedious enough).Additional information
Final checks