NestJS - AuthenticationHow can you securely invalidate a refresh token after logout in a NestJS app using a database?ADelete or mark the refresh token as revoked in the databaseBClear the access token from client localStorageCChange the user's passwordDDo nothing; tokens expire automaticallyCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand token invalidation on logoutRemoving or marking the refresh token revoked in DB prevents reuse after logout.Step 2: Evaluate other optionsClearing access token client-side does not affect refresh token; changing password is unrelated; relying on expiry alone is insecure.Final Answer:Delete or mark the refresh token as revoked in the database -> Option AQuick Check:Logout token invalidation = revoke in DB [OK]Quick Trick: Revoke refresh tokens in DB on logout [OK]Common Mistakes:Only clearing client tokens without server invalidationAssuming password change invalidates tokensRelying solely on token expiry
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