Authorization
How to protect routes, objects, pages and more.
In VitNode we're implementing a simple way to handle authorization.
Protecting routers
To protect routes for controllers you can set isProtect
for @Controllers
decorator. This will protect all routes in the controller.
Protecting per route
To protect a route (required sign in user), you need to add the @UseGuards(AuthGuard)
decorator for user auth or @UseGuards(AdminAuthGuard)
decorator for admin auth to the route.
Admin
Protecting routers
To protect routes for admin only, you can set isAdmin
for @Controllers
decorator. This will protect all routes in the controller.
[Admin] Protecting per route
To protect a route for admin only, you need to add the @UseGuards(AdminAuthGuard)
decorator to the route.
Current user data
When you are using @UseGuards(AuthGuards)
, @UseGuards(AdminAuthGuards)
or @Controllers
decorator with isAdmin
or isProtect
you can get access to the current user in the resolver by using the @CurrentUser()
decorator as param route.
Optional user data
If you want to make the user data optional, you have to add @OptionalAuth()
decorator to the route.