Asosiy/Lug'at/JWT (JSON Web Token)
security

JWT (JSON Web Token)

A compact, URL-safe means of representing claims to be transferred between two parties securely.

Sodda Hayotiy O'xshatish

"JWT is like a signed airline boarding pass: it contains your seat, gate, and security stamp, allowing gate agents to verify your access without querying central records."

Qanday ishlaydi va Nega kerak?

A JWT is composed of Header, Payload, and Signature separated by dots. It enables stateless authentication where the backend verifies claims cryptographically without database roundtrips.

Amaliy Kod Ko'rinishi

typescript
import { SignJWT, jwtVerify } from "jose";

// Token yaratish (Sign)
const secret = new TextEncoder().encode("secret_key");
const token = await new SignJWT({ userId: "u123", role: "developer" })
  .setProtectedHeader({ alg: "HS256" })
  .setExpirationTime("2h")
  .sign(secret);

Asosiy Xulosalar

Structure: Header.Payload.Signature
Enables true stateless scalability
Never store sensitive data (passwords) in Payload (it is only Base64-encoded)

Bog'liq Atamalar