From WordPress login to API call
Install the plugin
Add Simple JWT Login to WordPress, set a signing key, and turn on authentication.
Get a JWT
Your front end sends the user credentials to the REST API and gets a signed token back.
Call WordPress
Send the token as a Bearer header. WordPress treats the request as coming from that user.
const site = 'https://example.com/wp-json';
// 1. Get a JWT
const login = await fetch(site + '/simple-jwt-login/v1/auth', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email, password }),
});
const { data } = await login.json();
// 2. Call the WordPress REST API as that user
const me = await fetch(site + '/wp/v2/users/me', {
headers: { Authorization: 'Bearer ' + data.jwt },
});
Calling from the browser? Add your front-end origin in CORS and turn on the JWT middleware.
What a headless site needs
Login for any client
Log in by email or username, or with Google, GitHub, Facebook, and Auth0.
JWT authentication →User accounts over REST
Register users, reset passwords, and delete accounts without opening wp-login.php.
User registration →CORS built in
Choose which front-end origins can call the plugin and authenticate with a JWT.
CORS settings →Pick your stack
Headless WordPress questions
What is headless WordPress?
Headless WordPress uses WordPress to manage content and users, while a separate front end, such as a Next.js site or a mobile app, shows it. The two communicate through the REST API or GraphQL.
Why use JWT authentication with headless WordPress?
WordPress login cookies are made for pages that WordPress serves. A JWT is a signed token that any client can send with a request, so it also works for separate front ends, mobile apps, and servers.
Does it work with WooCommerce and WPGraphQL?
Yes. The same JWT can authenticate the WooCommerce REST and Store APIs and WPGraphQL requests.
Where should the front end store the JWT?
For websites, keep it in an HttpOnly cookie set by your server. For mobile apps, use the secure storage of the device. Avoid browser local storage for sensitive apps.
Is Simple JWT Login free?
Yes. It is free and open-source, forever, with no paid tier.