Hackforge Academy

Category: React • Beginner

Published on 30 Mar 2026

Explanation

JWT (JSON Web Token) is a secure way to transmit information between client and server as a JSON object 🔐. It is commonly used for authentication and authorization in web applications.

Code Example

Example JWT Token:
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.
eyJ1c2VySWQiOjEyMywibmFtZSI6IlByYXZlZW4ifQ.
SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

Explanation

A JWT token has three main parts: Header, Payload, and Signature 🧩. These parts are separated by dots (.) and encoded using Base64.

Code Example

Structure:
Header.Payload.Signature

Explanation

The Header section contains information about the token type and signing algorithm used (like HS256) ⚙️.

Code Example

{
  "alg": "HS256",
  "typ": "JWT"
}

Explanation

The Payload section contains user-related data such as user ID, role, or permissions 📄. This data is called claims.

Code Example

{
  "userId": 101,
  "role": "student",
  "exp": 1716239022
}

Explanation

The Signature ensures the token is secure and not modified during transmission 🛡️. It is created using the header, payload, and a secret key.

Code Example

HMACSHA256(
  base64UrlEncode(header) + "." + 
base64UrlEncode(payload),
  secret_key
)

Want structured learning with real projects?

Join our Weekend Live Workshop and become job-ready faster.