QuizzesAuthentication in a React App — Concept Check
intermediate
react

Authentication in a React App — Concept Check

Questions on Authentication in a React App. Where the token lives, how the app knows who you are before the first render, and what happens on a 401. The security decisions here outweigh the React ones.

8 minutes 8 questions Pass at 70%
Time Limit
8 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

8 questions on Authentication in a React App — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.In a React app, what is a potential drawback of storing an access token in localStorage?

    • AIt cannot be used across separate API domains.
    • BIt requires SameSite and CSRF protection.
    • CIt needs credentials: 'include' for cross-origin calls.
    • DIt can be accessed by any script on the page, making it vulnerable to XSS attacks.
  2. 2.A React app uses an httpOnly cookie for authentication. What must be ensured for cross-origin API calls?

    • ADecode the JWT on the client for authorization.
    • BUse credentials: 'include' to send cookies with requests.
    • CStore the token in localStorage for easy access.
    • DAllow JavaScript to read the cookie for verification.
  3. 3.A React app flashes a signed-out UI briefly on reload. What could be missing in the authentication implementation?

    • AUsing a refresh token in memory to avoid reloads.
    • BA third state to handle loading during session checks.
    • CStoring the token in localStorage for persistence.
    • DDecoding JWT on the client for immediate access.
  4. 4.What is a benefit of using an httpOnly cookie over a token in memory for session management?

    • AJavaScript cannot access it, reducing XSS risk.
    • BIt simplifies handling across multiple API domains.
    • CIt avoids the need for SameSite and CSRF protection.
    • DIt allows easy token refresh without reloads.
  5. 5.When handling a 401 error in a React app, what is a good practice to avoid multiple token refreshes?

    • AShare a single refresh promise across concurrent requests.
    • BRetry each request individually without sharing state.
    • CImmediately redirect to login on any 401 error.
    • DCache the token in localStorage to prevent errors.
  6. 6.What should be done during sign-out to ensure the next user doesn't see previous data?

    • AUse a memory-based token to avoid persistence.
    • BStore the token in sessionStorage for temporary access.
    • CClear the cache to remove cached responses.
    • DRely on the server to clear the session cookie.
  7. 7.A React app uses a refresh token in an httpOnly cookie. What is a benefit of this approach?

    • AIt works well across separate API domains and mobile clients.
    • BIt allows JavaScript to easily access the token.
    • CIt eliminates the need for SameSite protection.
    • DIt ensures the token is persisted even after reloads.
  8. 8.In a React app, what should you avoid doing with a JWT on the client side?

    • ASending it to the server for verification.
    • BUsing it to check user permissions.
    • CDecoding it for authorization decisions.
    • DReading it for display purposes like name or expiry.