Question
What is JWT and how is it used securely in frontend applications?
Answer
JWT (JSON Web Token) is a compact token format used for securely transmitting information between client and server.
A JWT contains:
Secure Usage
- Prefer storing tokens in HTTP-only cookies
- Avoid storing sensitive data in payload
- Use HTTPS always
- Implement token expiration and refresh strategy
fetch("/api/profile", {
headers: {
Authorization: `Bearer ${token}`,
},
});
Key Points
- JWTs are stateless
- Avoid localStorage for sensitive tokens
- Always validate tokens on backend