26/03/2026
How JWT Authentication Actually Works Step by Step?
Every time you log into an app something happens behind the scenes.
Most developers use it daily. Few can explain exactly what's happening step by step.
Let me tell you.
β Step 1: You send your credentials
You type your email and password and hit login.
That data travels from your browser to the server as an HTTP request.
IMPORTANT: the request must always travel over HTTPS. Never HTTP. Your password is sensitive. Encrypting it in transit is non negotiable.
β Step 2: The server verifies you
The server receives your credentials and checks them against the database.
But here's another important thing, your password is never stored as plain text. Ever.
It's stored as a hash. A one way encrypted version of your password. The server hashes what you just sent and compares it to the stored hash. If they match, you're in.
β Step 3: The server creates a token
Password matched. Now the server needs to remember you without asking for your password on every single request.
So it generates a JWT -- JSON Web Token.
A JWT is a small encoded string that contains your user info like your ID, your role, your expiry time. The server signs it with a secret key so nobody can fake one.
β Step 4: The token lives in your browser
The server sends the JWT back to your browser.
Your frontend stores it, usually in memory or an HTTP only cookie and attaches it to every future request automatically.
This is how the server knows it's still you without asking for your password again.
β Step 5: Every protected request gets verified
You click on your profile. Your frontend sends the request with the JWT attached.
The server receives it, verifies the signature, checks it hasn't expired, and reads your user info from inside it.
If everything goes fine, you get your data.
If the token is expired, tampered with, or missing, you get 401 error. Who are you?
The whole flow in one line:
You give your credentials β Hash check happens β Token generated β Token stored β Token verified on every request.
That's authentication. Not magic. Just a well designed handshake between your browser and your server.
Follow me for more dev concepts and insights.
P.S. This is exactly what happens in a MERN app when you use JWT with bcrypt. Now when you implement it, you'll know what every single line is actually doing.