Skip to content

Is there an Authentication Strategy Roadmap For Nitro File-Based API? #12412

@twofingerrightclick

Description

@twofingerrightclick

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:

  1. Create a login endpoint that gives user a JWT.
  2. Add a server middleware handler server/middleware/myAuthHandler.ts that checks the JWT and sets an appropriate prop on the event
  3. 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

  • Would you be willing to help implement this feature?
  • Could this feature be implemented as a module?

Final checks

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions