NestJS - AuthenticationHow can you modify the LocalStrategy to include additional user data in the validate method's return value?AReturn a boolean and fetch user data laterBModify the authService to return only user IDCThrow an exception with extra data attachedDReturn a custom object with user data after validationCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand validate method flexibilityThe validate method can return any object representing the authenticated user.Step 2: Customize return valueReturning a custom object with additional user data allows attaching more info to the request.Final Answer:Return a custom object with user data after validation -> Option DQuick Check:Return custom user object to include extra data [OK]Quick Trick: Return custom user object with extra info [OK]Common Mistakes:Returning only boolean instead of user objectThrowing exceptions to pass dataModifying service to limit data unnecessarily
Master "Authentication" in NestJS9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More NestJS Quizzes Authentication - Token generation and validation - Quiz 13medium Database with Prisma - Relations in Prisma - Quiz 13medium Database with TypeORM - Migrations - Quiz 8hard Database with TypeORM - Transactions - Quiz 13medium Interceptors - Cache interceptor - Quiz 13medium Interceptors - Logging interceptor - Quiz 9hard Interceptors - Interceptor interface - Quiz 7medium Middleware - Middleware ordering - Quiz 7medium Middleware - Global middleware - Quiz 6medium Middleware - Applying middleware to routes - Quiz 5medium