NestJS - AuthenticationWhich of the following is a best practice when storing refresh tokens in a NestJS application?AStore refresh tokens in localStorage for easy accessBStore refresh tokens in HTTP-only cookies to prevent JavaScript accessCSend refresh tokens in URL query parametersDStore refresh tokens in plain text files on the serverCheck Answer
Step-by-Step SolutionSolution:Step 1: Identify secure storage methods for refresh tokensHTTP-only cookies prevent JavaScript access, reducing XSS attack risks.Step 2: Evaluate other optionslocalStorage is vulnerable to XSS; URL parameters expose tokens in logs; plain text files are insecure.Final Answer:Store refresh tokens in HTTP-only cookies to prevent JavaScript access -> Option BQuick Check:Secure refresh token storage = HTTP-only cookies [OK]Quick Trick: Use HTTP-only cookies for refresh tokens [OK]Common Mistakes:Using localStorage which is vulnerable to XSSPassing tokens in URLs risking exposureStoring tokens insecurely on server
Master "Authentication" in NestJS9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More NestJS Quizzes Database with Prisma - Prisma setup in NestJS - Quiz 11easy Database with Prisma - Schema definition - Quiz 9hard Database with TypeORM - Query builder - Quiz 5medium Database with TypeORM - TypeORM module setup - Quiz 12easy Database with TypeORM - Query builder - Quiz 10hard Guards - Why guards control access - Quiz 4medium Middleware - Global middleware - Quiz 11easy Middleware - Global middleware - Quiz 2easy Pipes - Why pipes transform and validate input - Quiz 6medium Pipes - File validation pipe - Quiz 14medium