-
[Nest.js] Life Cycle - 2 GuardsNest.js 2021. 10. 7. 19:02
1. What is Guards?
Guards are for protecting our server based on our rules "internally".
What I mean is that we have to set up its own conditions, such as permissions, roles, etc.., in our project.
Guards works on here for Authentication/Authorization !!Guard is designed to return True or False only.
Why?, because there are no options need for authentication and authorization.
2. What Guards do ?
1. excuted after each middleware and before interceptors or pipes
2. Authentification
3. AuthorizationLet's see more for how we can set up internal security barriers.
3. Why is Nest.js Guards different from other components?
Guards is literally guarding a request whether user is validated or user has a permission.
We can make a barrier for a secure purpose via Guards.
Registration
Controller-scoped : @UseGuards(XXX)
Method-scoped : @UseGuards(XXX)
Global-scoped : app.useGlobalGuards(XXX) in main.ts
Examples
JWT, Passport, JwtStrategy, AuthGuard()
Conclusion
Guards component specific for authorization and authentification of a request.
send back a 403 if the component returns false
More details
look at my previous contents from 9 ~ 12 for more details
Authentification - https://docs.nestjs.com/security/authenticationAuthorization - https://docs.nestjs.com/security/authorization
Guards Implementation
'Nest.js' 카테고리의 다른 글
[Nest.js] Life Cycle - 1 Middleware (0) 2021.10.01 [Nest.js] Life Cycle - advanced approach (0) 2021.09.29 [Nest.js] simple project (0) 2021.09.27 [Nest.js] 16 - Log with Winston and WebHook (0) 2021.09.25 [Nest.js] 15 - Configuration (0) 2021.09.22