Recall & Review
beginner
What is a JWT (JSON Web Token)?
A JWT is a compact, URL-safe token that securely transmits information between parties as a JSON object. It is often used for stateless authentication in web apps.
Click to reveal answer
beginner
How does session-based authentication work?
Session-based authentication stores user data on the server after login. The server creates a session ID and sends it to the client as a cookie. The client sends this cookie with requests to prove identity.
Click to reveal answer
intermediate
What is one main advantage of JWT over sessions?
JWTs are stateless, meaning the server does not need to store session data. This makes scaling easier because any server can verify the token without shared storage.
Click to reveal answer
intermediate
What is a key security concern with JWTs compared to sessions?
JWTs are stored on the client side, often in localStorage or cookies, which can be vulnerable to theft via XSS attacks. Sessions keep sensitive data on the server, reducing this risk.
Click to reveal answer
intermediate
When might you prefer session strategy over JWT in Next.js apps?
Use sessions when you want simple, secure authentication with server-side control, especially if you need to easily revoke access or store complex user data securely.
Click to reveal answer
Which of these is true about JWT?
✗ Incorrect
JWTs store data on the client and do not require server-side session storage.
What does a session ID cookie do?
✗ Incorrect
The session ID cookie tells the server which session data belongs to the user.
Which is a security risk specific to JWTs?
✗ Incorrect
JWTs stored on the client can be stolen by malicious scripts via XSS.
Why might sessions be easier to revoke than JWTs?
✗ Incorrect
Since sessions live on the server, the server can delete them to revoke access immediately.
In Next.js, which strategy is better for scaling across many servers?
✗ Incorrect
JWTs are stateless and do not require shared session storage, making scaling easier.
Explain the main differences between JWT and session strategies for authentication.
Think about where data is stored and how that affects security and scaling.
You got /4 concepts.
Describe a scenario in a Next.js app where you would choose sessions over JWTs.
Consider security and control needs.
You got /4 concepts.