aladov3.13.0

Docs/Controllers

@withAuth

Attaches an authentication pipeline to a route.

TypeScript
@patch('/user/:id', { tags: ['User'] })
@withAuth(bearerAuth)
@defineRequest({ path: Id, body: UserDto })
async update(req: Request) {
  console.log(req.auth.user); // injected by the auth handler
}

Keep the route decorator (@patch here) above @withAuth: decorators apply bottom-up, and an @withAuth placed above it is refused at startup. See Registration rules.

Several strategies can be given (3.9.0): every argument is an alternative and one passing alternative is enough, an array argument is a group whose strategies must all pass:

TypeScript
@withAuth(bearerAuth, apiKeyAuth)              // a bearer token OR an API key
@withAuth([apiKeyAuth, bearerAuth])            // an API key AND a bearer token
@withAuth(allOf(apiKeyAuth, bearerAuth))       // the same group, spelled out
@withAuth([apiKeyAuth, bearerAuth], shareLink) // (API key AND bearer token) OR a share link

See Authentication for full config details and how several strategies are tried.