Bird
0
0

Why is it important to throw an UnauthorizedException inside the validate method when credentials are invalid?

hard📝 Conceptual Q10 of 15
NestJS - Authentication
Why is it important to throw an UnauthorizedException inside the validate method when credentials are invalid?
AIt creates a new user session
BIt signals Passport to reject the login attempt properly
CIt encrypts the password before returning
DIt automatically logs the user out
Step-by-Step Solution
Solution:
  1. Step 1: Understand Passport's error handling

    Throwing UnauthorizedException tells Passport the authentication failed.
  2. Step 2: Effect on login flow

    This causes Passport to reject the login attempt and respond with an error.
  3. Final Answer:

    It signals Passport to reject the login attempt properly -> Option B
  4. Quick Check:

    Throw UnauthorizedException to reject login [OK]
Quick Trick: Throw UnauthorizedException to reject invalid login [OK]
Common Mistakes:
  • Thinking it logs user out
  • Confusing exception with encryption
  • Assuming it creates sessions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes