Pottr/Docs
Topic:App Users & JWT Authentication
Authentication
.md

App Users & JWT Authentication

Decoupled end-user authentication, JWT lifecycles, profile management, and password reset flows.

How are App Users Different from WordPress Admins?

Pottr provides an independent authentication layer designed specifically for end-users of your custom application:

  • No WordPress Admin Access: App users cannot log into /wp-admin and have no core WordPress capabilities.
  • No wp_users Bloat: App users are stored in dedicated application authentication tables, keeping WordPress administration clean.
  • Custom Profile Fields: Blueprints allow declaring custom fields on user accounts (e.g. full_name, company, avatar_url).
  • Stateless JWT Tokens: Authenticated via 15-minute HS256 JWT access tokens and 30-day hashed refresh tokens.

App Header Requirement (X-Pottr-App)

Every authentication endpoint requires an application identifier passed in the X-Pottr-App: <app_slug> request header (or an app string in the JSON body).

Authentication Endpoints

1. User Signup

POST/auth/signupPublic Key Required

Registers a new app user. Password must be at least 8 characters. Returns 201 Created with tokens.

signup.js
const res = await fetch('https://example.com/wp-json/pottr/v1/auth/signup', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${PUBLIC_KEY}`,
    'X-Pottr-App': 'task-manager',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    email: 'alex@example.com',
    password: 'securePassword123',
    full_name: 'Alex Smith'
  })
});

2. User Login

POST/auth/loginPublic Key Required

Authenticates user credentials. Signup and login return the same shape:

Token Response
{
  "user": { "id": 12, "email": "alex@example.com", "full_name": "Alex Smith" },
  "access_token": "eyJ...",
  "refresh_token": "64_character_hex_refresh_token",
  "token_type": "Bearer",
  "expires_in": 900
}

Send the access token in the X-Pottr-User-Token header (alongside your public key). Passwords are never returned.

3. Current User Profile

GET/auth/meUser JWT Required

4. Token Refresh

POST/auth/refreshPublic Key Required

Refresh tokens are single-use. Each refresh returns a new access token and a new refresh token; store the new one and discard the old. Presenting an already-used refresh token is treated as theft: Pottr revokes that whole session and returns 401 token_breach_detected.

Request Body
{
  "refresh_token": "64_character_hex_refresh_token"
}

5. Logout

POST/auth/logoutUser JWT Required

Revokes the current device session. Pass ?all=true (or { "all": true }) to sign the user out everywhere. Outstanding access tokens are invalidated immediately.

6. Sessions

GET/auth/sessionsUser JWT Required

Lists the user’s active device sessions with IP, browser and an is_current flag. End one with:

DELETE/auth/sessions/{family_id}User JWT Required

Rate Limits

Signup, login and password-reset routes are rate limited per IP. Exceeding the limit returns 429 rate_limited.

Password Reset Flow

  1. Request Reset Email (POST /auth/forgot-password): Client submits { "email": "user@example.com" }. Pottr generates a secure 1-hour single-use transient token and sends a reset email via WordPress wp_mail(). Always returns 200 { success: true } to prevent email enumeration.

  2. Complete Password Reset (POST /auth/reset-password): Client submits { "email": "...", "token": "...", "password": "newPassword" }. Pottr validates the token, updates the password hash, immediately destroys the token, and revokes active sessions.