šŸš€

AI SaaS Starter - Build an AI SaaS in Days

Grab a production-ready starter project with all integrations.

šŸ“¢

Advertise Your Company Here

Click now to email us to advertise in this spot and reach thousands of frontend developers.

šŸš€

AI SaaS Starter - Build an AI SaaS in Days

Grab a production-ready starter project with all integrations.

šŸ“¢

Advertise Your Company Here

Click now to email us to advertise in this spot and reach thousands of frontend developers.

Blog/NotesConcept

How does JWT (JSON Web Token) Authentication work - Pros & Cons

Understand the JWT(JSON Web Token) and how JWT decode works. It also covers how the end-to-end JWT authentication works between client & server, along with the pros and cons of using JWT.

Intermediate

Frontendgeek

Last Updated Feb 6, 2026


How does JWT (JSON Web Token) Authentication work - Pros & Cons

JWT(JSON Web Token) is currently becoming the standard of web authorization, where the token(JWT) carries all the required information along with the token and on the server, the information is decoded by the server using a key.

In this post, we will learn about JWT Token, its structure and pros-cons, so that you can use JWT token for authorization confidently 

What is JWT(JSON Web Token)?

A JSON Web Token (JWT) is a compact, URL-safe way of securely transmitting information between client and server, so that the server gets the information that is required to authorise the request from client to server.

You can understand JWT tokens with an analogy of a digital boarding pass āœˆļø . Once you get a boarding pass after logging in, you keep showing it to prove your identity until it expires.

A JWT Token contains three parts:

  1. Header → contains metadata like the algorithm used for signing
  2. Payload → contains the actual data like userId, email, and roles, which the client wants to transfer.
  3. Signature → verifies the token hasn’t been tampered with.

Example structure:

A JWT (JSON Web Token) is made up of three parts: Each part is Base64URL encoded and separated by dots (.) notation.

<header>.<payload>.<signature>

JWT decoded Example

Here’s a sample JWT token where parts are separated by dot(.):

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.
eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMn0.
KMUFsIDTnFmyG3nMiGM6H9FNFUROf3wh7SmqJp-QV30

Decoded Values

When the JWT token decoded, it contains 3 JSON objects related to header, payload and singnature.

Note: Follow to JWT token decode online JWT Decode Applications

Decoding JWT Token

1. Header

JWT header part contains 2 key value pair, one is the algorithm which is used to sign this token and another one is the type of token which is JWT

  • alg: Algorithm used to sign the token (HS256 = HMAC + SHA-256).
  • typ: Type of token (JWT).
{
  "alg": "HS256",
  "typ": "JWT"
}

2. Payload

Payload contains the actual data, that will going to send from client to server. This is the data which is used to do the authorization of the service.

  • "sub": Subject (usually the user ID).
  • "name": User’s name.
  • "role": Role of the user (admin, user, etc.).
  • "exp": Expiry timestamp (Unix epoch).
{
  "sub": "1234567890",
  "name": "John Doe",
  "role": "admin",
  "exp": 1716239022
}

3. Signature

The server uses this signature to verify that the token hasn’t been altered.

SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

How does JWT (JSON Web Token) Authentication work?

Here is the flow diagram to understand how JWT token works between client and server to provide authorization to the requests.

Flow diagram how JWT works

Here is the end-to-end JWT authentication flow looks like

  1. User provides credentials - User logs in with valid credentials.
  2. Server validation & JWT generation - Server validates and generates a JWT (with header, payload, and signature).
  3. Sent JWT back to client - This token is sent back to the client and stored (usually in localStorage or cookies).
  4. Send JWT as Auth token -  For every request, the client attaches the token in the "Authorization" header.
  5. Server verification - Server verifies the signature to ensure it hasn’t been tampered with.
  6. Server authorize request - If valid → āœ… access granted. If not → āŒ access denied.

What are some pros & cons of using JWT Token-based Authentication?

let's understand the important advantages which JWT token provides instead of cookie-based authentication, and in which cases JWT token is not a better choice 

Pros of JWT

āœ… Stateless

  1. No need for the server to store session data.
  2. Works perfectly with microservices and distributed systems.

āœ… Scalable

  1. Easy to use with APIs, SPAs (React/Next.js), and mobile apps.
  2. Doesn’t rely solely on browser cookies.

āœ… Compact  & Fast

  1. Base64 encoded → small enough to send in HTTP headers.
  2. Less overhead compared to storing session IDs.

āœ… Flexible Payload

  1. Can carry custom claims like roles, permissions, tenant info, etc.

Cons of JWT

āŒ Difficult to revoke if stolen

  1. Once issued, you can’t easily “kill” a token if the token gets compromised.

āŒ Size bloat

  1. Storing too much data in the payload can slow down the API requests, beacause of the more data transfer over the network.

āŒ Security risks

  1. If stored in localStorage, vulnerable to XSS.

āŒ Expiry handling

  1. Needs proper refresh token mechanism and required extra effort to keep it fresh.

Learn Next: More authorization techniques

  1. Notes for web authorization techniques

About the Author

Frontendgeek

Frontendgeek

One of the leading, Frontend platform to help frontend devs to prepare and ace all rounds of frontend interview with ease.

šŸš€

Love this content? Share it!

Help others discover this resource

Comments

Be the first to share your thoughts!

Guest User

Please login to comment

0 characters


No comments yet.

Start the conversation!

Share Your Expertise & Help the Community!

Build Your Portfolio

Help the Community

Strengthen Your Skills

Share your knowledge by writing a blog or quick notes. Your contribution can help thousands of frontend developers ace their interviews and grow their careers! šŸš€


Other Related Blogs

Polyfill for map, filter, and reduce in JavaScript

Anuj Sharma

Last Updated Oct 2, 2025

Explore Polyfill for map, filter and reduce array methods in JavaScript. A detailed explanation of Map, filter and reduce polyfills in JS helps you to know the internal working of these array methods.

Flatten Nested Array in JavaScript using Recursion

Anuj Sharma

Last Updated Nov 24, 2025

Understand step by step how to flatten nested array in javascript using recursion, also explore the flatten of complex array of object.

Master Hoisting in JavaScript with 5 Examples

Alok Kumar Giri

Last Updated Jun 2, 2025

Code snippet examples which will help to grasp the concept of Hoisting in JavaScript, with solutions to understand how it works behind the scene.

Implement useFetch() Custom Hook in React (Interview)

Anuj Sharma

Last Updated Nov 23, 2025

Find the step-by-step explanation of the useFetch custom hook in React that helps in fetching the data from an API and handling loading, error states.

setTimeout Polyfill in JavaScript - Detailed Explanation

Anuj Sharma

Last Updated Aug 3, 2025

Explore the implementation of setTimeout in JavaScript with a detailed explanation for every step. Understand all scenarios expected to implement the setTimeout polyfill.

Explained Web Authorization Techniques - Session & JWT

Anuj Sharma

Last Updated Dec 16, 2025

Understand important web authorization techniques to enhance role-based authentication for any web application with popular techniques like Session & JSON Web Token (JWT)

Stay Updated

Subscribe to FrontendGeek Hub for frontend interview preparation, interview experiences, curated resources and roadmaps.

FrontendGeek
FrontendGeek

All in One Preparation Hub to Ace Frontend Interviews. Master JavaScript, React, System Design, and more with curated resources.

Consider Supporting this Free Platform

Buy Me a Coffee

Product

HomeFrontend InterviewInterview ExperienceBlogsToolsLeaderboard

Tools

CSS Image FilterPixelate ImageAspect Ratio CalculatorBox Shadow GeneratorCSS Gradient GeneratorNeumorphism GeneratorExplore More Tools →

Ā© 2026 FrontendGeek. All rights reserved