All Recipes
StarVerified Developer Solution • 100% Offline
JWT Decoder & Inspector

Debug "JsonWebTokenError: invalid signature" in Node.js

Learn how to debug and fix the invalid signature error when verifying JSON Web Tokens (JWT) in your backend.

The Problem (Error Root Cause)Exception

Your server is rejecting a JWT with "invalid signature". This happens when the token was tampered with, the secret key mismatches, or the signing algorithm differs.

Identified via runtime validation & stack traces
The Solution (Step-by-Step Fix)Verified

Decode the token header and payload to verify the algorithm used (`HS256`, `RS256`). Check if the payload data matches your expectations before verifying the signature locally.

Deterministic, non-destructive resolution

Code Standard: Bad Pattern vs Verified Fix

Live Syntax
Anti-Pattern vs Verified Fix
1// ❌ Bad: Blindly verifying
2const decoded = jwt.verify(token, process.env.SECRET);
3
4// ✅ Good: Check token structure first
5const decoded = jwt.decode(token, { complete: true });
6console.log(decoded.header.alg); // e.g., 'RS256'

Test and resolve this using JWT Decoder & Inspector

Execute directly in your browser memory. Zero API keys, zero network tracking, completely client-side.

Launch JWT Decoder & Inspector

Frequently Asked Questions

Q:What does invalid signature mean?

It means the hash of the payload and header does not match the signature provided, usually due to a wrong secret key.

Q:Can I decode a token without the secret?

Yes! The header and payload of a JWT are just Base64Url encoded. You can view them using our JWT Decoder tool.

Related Troubleshooting Guides

View Directory