0
0
NestJSframework~5 mins

Local strategy (username/password) in NestJS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the Local strategy in NestJS authentication?
The Local strategy is used to authenticate users by verifying their username and password during login.
Click to reveal answer
beginner
Which NestJS package provides the Local strategy for username/password authentication?
The @nestjs/passport package provides the Local strategy by integrating Passport.js with NestJS.
Click to reveal answer
intermediate
In a Local strategy, what method is typically overridden to validate user credentials?
The validate() method is overridden to check the username and password against stored user data.
Click to reveal answer
intermediate
What does the validate() method return if the user credentials are correct?
It returns the user object without the password, which Passport attaches to the request object.
Click to reveal answer
intermediate
How does NestJS use the Local strategy in a login route?
NestJS uses the @UseGuards(AuthGuard('local')) decorator to protect the login route and trigger the Local strategy.
Click to reveal answer
What does the Local strategy in NestJS authenticate?
AAPI keys
BOAuth tokens
CUsername and password
DJWT tokens
Which method do you override in a Local strategy to check user credentials?
Alogin()
Bauthenticate()
Cauthorize()
Dvalidate()
What happens if validate() returns null or throws an error in Local strategy?
AAuthentication fails
BUser is authenticated
CUser is redirected to home
DSession is created
Which decorator applies the Local strategy guard to a route in NestJS?
A@LocalStrategy()
B@UseGuards(AuthGuard('local'))
C@AuthLocal()
D@UseLocal()
What package must be installed to use Local strategy in NestJS?
A@nestjs/passport
Bpassport-google-oauth
Cpassport-local
D@nestjs/jwt
Explain how the Local strategy works in NestJS for username and password authentication.
Think about how NestJS checks user login details step by step.
You got /5 concepts.
    Describe how to protect a login route using the Local strategy in NestJS.
    Focus on the decorator and guard usage.
    You got /4 concepts.