Works with any JavaScript framework
A zero-dependency library with full ESM and CommonJS support — works in React, Vue, Angular, Svelte, or a plain script tag.
Vanilla JS
React / Next.js
Vue / Nuxt
AngularEverything in the token lifecycle
Async / await API covering authentication, registration, and the full token lifecycle.
Exchange credentials for a JWT
Authenticate any WordPress user by email or username and receive a signed JWT. Store it in memory or localStorage and attach it to every subsequent request via the Authorization header.
npm →// Authenticate a user and get a JWT import SimpleJwtLogin from 'simple-jwt-login'; const client = new SimpleJwtLogin({ siteUrl: 'https://your-wordpress-site.com', authCode: 'your-auth-code', }); const response = await client.auth.login({ email: 'user@example.com', password: 'secret', }); const jwt = response.data.jwt;
Built for real JavaScript workflows
From React SPAs to server-side Node.js middleware — the client handles the auth layer so you can focus on your application.
React / Next.js
Authenticate users from a React SPA or a Next.js app. Store the JWT in a context provider and attach it to every fetch or Axios call to your WordPress REST API.
import SimpleJwtLogin from 'simple-jwt-login';
const client = new SimpleJwtLogin({
siteUrl: process.env.NEXT_PUBLIC_WP_URL,
authCode: process.env.NEXT_PUBLIC_SJL_AUTH_CODE,
});
// In your login handler
const { data } = await client.auth.login({ email, password });
localStorage.setItem('jwt', data.jwt);
// In your API helper
const res = await fetch(`${wpUrl}/wp-json/wp/v2/posts`, {
headers: { Authorization: localStorage.getItem('jwt') },
});Vue / Nuxt
Integrate JWT authentication into a Vue 3 or Nuxt application. Use a Pinia store to hold the token and a composable to expose login/logout actions.
// stores/auth.js (Pinia)
import { defineStore } from 'pinia';
import SimpleJwtLogin from 'simple-jwt-login';
const client = new SimpleJwtLogin({
siteUrl: import.meta.env.VITE_WP_URL,
authCode: import.meta.env.VITE_SJL_AUTH_CODE,
});
export const useAuthStore = defineStore('auth', {
state: () => ({ jwt: null }),
actions: {
async login(email, password) {
const res = await client.auth.login({ email, password });
this.jwt = res.data.jwt;
},
},
});Node.js / Express
Use the client on the server side to validate tokens in Express middleware, script WordPress user creation in CI, or build a BFF that proxies authenticated WP API calls.
import SimpleJwtLogin from 'simple-jwt-login';
const client = new SimpleJwtLogin({
siteUrl: process.env.WP_URL,
authCode: process.env.SJL_AUTH_CODE,
});
// Express middleware
app.use(async (req, res, next) => {
const jwt = req.headers.authorization;
if (!jwt) return res.status(401).json({ error: 'Missing token' });
const result = await client.auth.validateToken({ jwt });
if (!result.success) return res.status(401).json({ error: 'Invalid token' });
next();
});Up and running in minutes
Requirements
- Node.js12+
- npm / yarnany
- Simple JWT Loginactive
- WordPress4.4+
Add the package to your project.
npm install simple-jwt-login # or yarn add simple-jwt-login
Pass your WordPress site URL and Simple JWT Login Auth Code.
import SimpleJwtLogin from 'simple-jwt-login'; const client = new SimpleJwtLogin({ siteUrl: 'https://your-wordpress-site.com', authCode: 'your-auth-code', });
Use the async API to authenticate, register, or manage tokens.
const { data } = await client.auth.login({ email: 'user@example.com', password: 'secret', }); const jwt = data.jwt;
Complete method reference
All available client methods at a glance.
auth.login()Exchange credentials for a JWT tokenauth.validateToken()Verify a token signature and expiryauth.refreshToken()Get a new token from an expiring oneauth.revokeToken()Permanently invalidate a tokenusers.register()Create a new WordPress user accountusers.delete()Delete a user via a verified JWTusers.autologin()Generate a one-click auto-login URLusers.changePassword()Change the authenticated user's passwordusers.resetPassword()Trigger a password reset emailAdd JWT to your JavaScript app today
One npm install and a few lines of code — that's all it takes to add WordPress JWT authentication to any JavaScript project.