Decorators
Every decorator exported from `@ackplus/nest-auth`.
Auth decorators
@Auth(optional?: boolean)
Marks a route as requiring authentication. Pass true to make auth optional — if the user is logged in, request context is populated; if not, the route still runs.
Pairs with NestAuthAuthGuard — apply that guard once globally, and use @Auth() and @Public() to opt routes in or out.
@Public()
Bypass auth on a specific route. Useful when the global guard is NestAuthAuthGuard and you have a handful of unauthenticated endpoints (/health, /auth/login).
@SkipMfa()
Bypass MFA enforcement on a specific route. Used on /auth/mfa/verify itself (the verify endpoint can't require MFA — that's circular).
Authorization decorators
@NestAuthRoles(roles, guard?)
Require one of the listed roles.
When roleGuards: ['web', 'api'] is configured, omitting the second arg targets the first (the "default") guard.
@NestAuthPermissions(permissions, requireAll?)
Require one or all of the listed permissions.
Tenant context decorators
For use in controller method signatures.
| Decorator | Returns |
|---|---|
@CurrentTenantId() | string — active tenant ID |
@CurrentTenant() | NestAuthTenant — full tenant entity |
@CurrentUserAccess() | NestAuthUserAccess — current user's per-tenant membership row |
@CurrentMembership() | Alias for @CurrentUserAccess() |
User decorators
@CurrentUser()
Inject the authenticated user. Throws if @Auth() isn't applied (or if @Auth(true) matched no user).
Admin console decorators
@CurrentAdmin()
Inside admin-console controllers, returns the authenticated admin user.
Practical patterns
Apply the guard globally, opt out for public routes
Multi-guard role checks
When both decorators are present, both must pass.
Related
- Guards.
- RBAC.
- Multi-Tenancy — tenant decorators in context.