-
-
Notifications
You must be signed in to change notification settings - Fork 2
Decorators
Protects a route or controller using the FirebaseGuard. It ensures that the request contains a valid Firebase ID token in the Authorization: Bearer <token> header.
Usage:
@Auth()
@Get('secure')
getSecureData() { ... }Extracts the decoded ID token from the request object. This provides access to user information like uid, email, email_verified, and any custom claims.
Important
This decorator requires the route to be protected by @Auth() (or FirebaseGuard) to function. Without the guard, the user object is not attached to the request.
Usage:
@Injectable()
@Controller('user')
export class UserController {
@Get('me')
getMe(@FirebaseUser() user: DecodedIdToken) {
return {
uid: user.uid,
email: user.email,
};
}
}Specifies the roles required to access a route. The user must have at least one of the specified roles to be granted access.
Requirements:
-
validateRole: truemust be set inFirebaseAdminModuleconfiguration. - The user must have a custom claim (default key:
'roles') containing an array of roles.
Usage:
@Auth()
@Roles('ADMIN', 'SUPERUSER')
@Get('admin-panel')
getAdminPanel() { ... }Extracts the roles claim array from the authenticated user's token or custom claims. This is useful if you want to inspect the user's roles within your controller logic.
Usage:
@Get('my-roles')
getMyRoles(@FirebaseRolesClaims() roles: string[]) {
return roles;
}GitHub Repository | Issues | Releases
If you find this project useful, you can support it by buying me a coffee ☕️. If you can't contribute financially, a ⭐ on the repo is also greatly appreciated!
MIT License © 2024 Tomás Alegre