Skip to main content

Headless WordPress authentication with JWT

Keep WordPress for content and users. Build the front end with any framework, and log users in through the REST API.

How it works

From WordPress login to API call

  1. Install the plugin

    Add Simple JWT Login to WordPress, set a signing key, and turn on authentication.

  2. Get a JWT

    Your front end sends the user credentials to the REST API and gets a signed token back.

  3. Call WordPress

    Send the token as a Bearer header. WordPress treats the request as coming from that user.

Log in and call WordPress
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.

Features

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 →

Protected endpoints

Require a valid JWT for any WordPress REST API route.

Endpoint protection →

Token lifecycle

Refresh tokens to keep users logged in, and revoke them on logout.

Refresh tokens →

CORS built in

Choose which front-end origins can call the plugin and authenticate with a JWT.

CORS settings →

Two-factor login

Ask for a second factor before WordPress issues the final token.

Two-factor login →
Examples

Pick your stack

Next.js

Server-side login with an HttpOnly cookie.

Next.js example →

Flutter

Mobile login with secure token storage.

Flutter example →

React Native

Expo app with secure token storage.

React Native example →

React

Browser login with a Vite app.

React example →

Vue

Browser login with a Vue 3 app.

Vue example →

Angular

Browser login with HttpClient.

Angular example →

JavaScript

A todo app with no framework.

JavaScript example →

WooCommerce

Products, cart, and checkout with a JWT.

Headless store example →

WPGraphQL

Authenticated queries and mutations.

WPGraphQL guide →

AI agents

Manage the plugin through MCP.

MCP guide →
FAQ

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.

Go headless with WordPress

Free and open-source, forever.