Skip to main content

Refresh the access token

Access tokens are short-lived. Use the refresh method to obtain a new one without requiring the user to log in again. The SDK handles caching and prevents concurrent refresh calls across browser tabs automatically.
The refresh flow is protected by DPoP (Demonstration of Proof-of-Possession). The SDK generates a cryptographic key pair and signs each refresh request with a proof that binds the request to the client. This protects against:
  • Token theft — A stolen refresh cookie is unusable without the private key, which is bound to the browser and never transmitted
  • Token replay — Each DPoP proof includes a unique identifier and timestamp, preventing reuse
  • Man-in-the-middle attacks — The proof binds to the HTTP method and URL, so it cannot be replayed against a different endpoint
  • Token export — The key pair is non-extractable, meaning it cannot be copied from the browser to another device
To force the next refresh call to hit the backend (bypassing the local cache), invalidate the cache first:
In the login App.jsx above, add decode to your import (import { ..., decode } from "@prelude.so/js-sdk") and replace the article block with:
Each click fetches a new access token and updates the decoded token content.

Log out

When a user logs out, call logout to revoke the session and clear the local cache:
Add a logout button next to the refresh button in the authenticated view:
The user is redirected back to the login form after logout.

List sessions

Retrieve all active sessions for the authenticated user:
Each session contains id, device_type, device_model, os_version, country_code, created_at, last_seen_at, and expires_at.
Replace src/App.jsx with:
src/App.jsx

Revoke sessions

Use revokeSessions to revoke sessions. The target parameter controls which sessions are revoked:
Building on the list sessions example above, add revocation controls. Replace src/App.jsx with:
src/App.jsx

Verify access tokens on your backend

Your backend should verify the JWT access token on each authenticated request. Retrieve the public keys from your application’s JWKS endpoint:
Use any standard JWT library to verify the token signature against these keys.