auth0-spa-js
CLAUDE.md1k starsChanged 3 years agoMITView on GitHub
This document provides context and guidelines for AI coding assistants working with the auth0-spa-js codebase. You are a TypeScript SDK engineer working on auth0-spa-js, the Auth0 authentication SDK for browser-based single-page applications. You write small, well-tested, tree-shakeable code, and you keep the browser SPA use case — where the SDK runs in a hostile environment — front of mind. Apply these on every task in this repo — they keep changes correct, small, and reviewable. auth0-spa-js is the Auth0 SDK…
Adopted by
Steady: 0 new projects took it in the last 4 weeks, none the 4 weeks before.thin data
Who's talking about auth0/auth0-spa-js
- Stack Overflow“Best way to mock authenticated (auth0) API calls in Cypress”Stack Overflow · Feb 11, 2022 · 6 votes
- Stack Overflow“Auth0-spa-js must run on a secure origin. How to work around for AWS initial deployment?”Stack Overflow · Dec 6, 2022 · 5 votes
- Stack Overflow“Cypress cannot request API or display content with the new auth0-spa-js package”Stack Overflow · Aug 23, 2019 · 5 votes
- Stack Overflow“Auth0 "The JWT string must contain two dots"”Stack Overflow · Apr 2, 2022 · 4 votes
- auth0/auth0-react“user is not updated after getAccessTokenSilently({ignoreCache: true})”GitHub · Sep 4, 2020 · 4 reactions
The biggest 5 of 61 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 61
Talked about on GitHub and Stack Overflow (61 times).
On GitHub · 50
- Sep 4, 2020user is not updated after getAccessTokenSilently({ignoreCache: true}) — auth0/auth0-react4 reactions · 5 comments
- Oct 18, 2021bug: Live Reload not working on Android with Auth0 https login — ionic-team/capacitor2 reactions · 3 comments
- Oct 31, 2019Auth0 SPA + Apollo Client / Link — auth0-samples/auth0-javascript-samples2 reactions · 5 comments
- Aug 31, 2021Update dependencies! — uilibrary/matx-react1 reaction · 2 comments
- Jul 5, 2021[SDK-2603] Expose custom caching options from Auth0 SPA SDK — auth0/auth0-react1 reaction · 1 comment
45 more on GitHub
- Jan 30, 2021feat: added buildAuthorizeUrl and buildLogoutUrl from auth0-spa-js — auth0/auth0-react1 reaction · 3 comments
- Nov 16, 2020Limiting State-Reading URLs/Paths — auth0/auth0-angular1 reaction · 4 comments
- Oct 30, 2020Proxy missing identifiers when making Auth0 request on SPA — DevExpress/testcafe1 reaction · 9 comments
- Nov 7, 2026build(deps): bump the runtime-minor-patch group across 1 directory with 5 updates — HoffmanEngineering/3d-print-log-ui0 reactions
- Nov 6, 2026chore(deps): bump the npm-minor-patch group across 1 directory with 7 updates — vindicara-inc/projectair0 reactions
- Nov 6, 2026feat: add revokeRefreshToken functionality and update documentation — auth0/auth0-vue0 reactions · 1 comment
- Nov 5, 2026CRASH — precision-sustainable-ag/dst-crash0 reactions
- Nov 5, 2026CRASH — precision-sustainable-ag/dst-crash0 reactions
- Nov 4, 2026Bump the "npm" group with 1 update across multiple ecosystems — patkub/auth0-obo-flow-sample0 reactions
- Nov 3, 2026chore(deps): bump @auth0/auth0-spa-js from 2.29.0 to 2.30.0 — merkaly-io/nuxt0 reactions
- Nov 2, 2026chore(deps-dev): bump @auth0/auth0-spa-js from 2.29.0 to 2.30.0 — auth0/auth0-react-router0 reactions
- Nov 2, 2026Bump @auth0/auth0-spa-js from 2.24.1 to 2.30.0 in /client — superdesk/newsroom-app-cp0 reactions
- Nov 1, 2026Bump the frontend-runtime group in /web with 15 updates — SmarterVote/SmarterVote0 reactions
- Nov 1, 2026Bump the javascript-dependencies group with 6 updates — letsbuilda/letsbuilda.dev0 reactions · 1 comment
- Oct 31, 2026CRASH — precision-sustainable-ag/dst-crash0 reactions
- Oct 31, 2026chore(deps): bump the npm-minor-patch group across 1 directory with 11 updates — BeyondITL/contentine-create0 reactions
- Oct 27, 2026chore(deps): bump @auth0/auth0-spa-js from 2.28.1 to 2.29.0 — merkaly-io/nuxt0 reactions
- Oct 26, 2026chore(deps-dev): bump @auth0/auth0-spa-js from 2.28.4 to 2.29.0 — auth0/auth0-react-router0 reactions
- Oct 26, 2026build(deps-dev): bump @auth0/auth0-spa-js from 2.28.3 to 2.30.0 — shuangyan123/tutorbench0 reactions · 1 comment
- Oct 26, 2026Bump @auth0/auth0-spa-js from 2.24.1 to 2.29.0 in /client — superdesk/newsroom-app-cp0 reactions · 1 comment
- Oct 25, 2026CRASH — precision-sustainable-ag/dst-crash0 reactions
- Oct 21, 2026CRASH — precision-sustainable-ag/dst-crash0 reactions
- Oct 19, 2026build(deps-dev): bump @auth0/auth0-spa-js from 2.28.3 to 2.28.4 — shuangyan123/tutorbench0 reactions · 1 comment
- Oct 19, 2026Bump @auth0/auth0-spa-js from 2.28.3 to 2.28.4 in the production-dependencies group across 1 directory — pbs-tech/relay-synth-app0 reactions
- Oct 19, 2026Bump @auth0/auth0-spa-js from 2.24.1 to 2.28.4 in /client — superdesk/newsroom-app-cp0 reactions · 1 comment
- Oct 19, 2026build(deps): bump @auth0/auth0-spa-js from 2.28.3 to 2.28.4 — auth0/auth0-angular0 reactions · 2 comments
- Oct 18, 2026CRASH — precision-sustainable-ag/dst-crash0 reactions
- Oct 14, 2026CRASH — precision-sustainable-ag/dst-crash0 reactions
- Oct 12, 2026CRASH — precision-sustainable-ag/dst-crash0 reactions
- Oct 7, 2026build(deps): bump @auth0/auth0-spa-js from 2.27.0 to 2.28.2 — pbuchman/multi-device-context0 reactions
- Oct 6, 2026CRASH — precision-sustainable-ag/dst-crash0 reactions
- Oct 5, 2026Bump the production-dependencies group across 1 directory with 4 updates — williamhullinger/integrity-transmissions-site0 reactions · 1 comment
- Oct 4, 2026CRASH — precision-sustainable-ag/dst-crash0 reactions
- Oct 3, 2026CRASH — precision-sustainable-ag/dst-crash0 reactions
- Oct 2, 2026CRASH — precision-sustainable-ag/dst-crash0 reactions
- Oct 1, 2026CRASH — precision-sustainable-ag/dst-crash0 reactions
- Sep 30, 2026CRASH — precision-sustainable-ag/dst-crash0 reactions
- Sep 28, 2026CRASH — precision-sustainable-ag/dst-crash0 reactions
- Sep 24, 2026Bump the minor group across 1 directory with 8 updates — socialimpactisp/Our-Net-Frontend0 reactions
- Sep 23, 2026CRASH — precision-sustainable-ag/dst-crash0 reactions
- Sep 22, 2026CRASH — precision-sustainable-ag/dst-crash0 reactions
- Aug 19, 2026feat: add SDK reference docs for auth0-react and auth0-spa-js — auth0/docs-v20 reactions · 3 comments
- Oct 27, 2025Bump @auth0/auth0-spa-js from 2.6.0 to 2.8.0 in /src/LogMkWeb — timothydodd/LogMk0 reactions
- Oct 27, 2025build(deps): bump @auth0/auth0-spa-js from 1.22.5 to 2.8.0 — skyYaga/skdvin-webapp0 reactions · 2 comments
- Sep 26, 2025Connect demo — auth0-samples/auth0-javascript-samples0 reactions
On Stack Overflow · 11
- Feb 11, 2022Best way to mock authenticated (auth0) API calls in Cypress6 votes · 1 answer
- Dec 6, 2022Auth0-spa-js must run on a secure origin. How to work around for AWS initial deployment?5 votes
- Aug 23, 2019Cypress cannot request API or display content with the new auth0-spa-js package5 votes · 1 answer
- Apr 2, 2022Auth0 "The JWT string must contain two dots"4 votes · 2 answers
- Jan 15, 2021auth0 auth0-spa-js must run on a secure origin angular3 votes
6 more on Stack Overflow
- Aug 4, 2023Auth0 email magic link `Error: Invalid state` for vue1 vote
- Apr 18, 2021Auth0 - Disable user profile cache1 vote
- Dec 10, 2019Setting up React app using Typescript with Auth01 vote · 1 answer
- Nov 23, 2022Accessing useAuth0 hook data via redux thunk action with axios instance0 votes
- Oct 29, 2020Uncaught Error: Uncaught (in promise): TypeError: Super expression must either be null or a function in Angular v60 votes
- Mar 12, 2020Implement Auth0 in http (non-secure mode)-3 votes
In this repositoryOne other file it gives its agents.
- AGENTS.mdAGENTS.md
The file
We split this CLAUDE.md into the rules it gives an agent
9 rules. About 0 are common, 5 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Distinctive: line 16
Simplicity first: Write the minimum code that solves the stated problem — no speculative features, single-use abstractions, premature …
- Very specific: line 62
Run npm test and npm run lint before committing
- Very specific: line 63
Add Jest specs for new behavior.
- Very specific: line 64
Update README.md and the relevant file under examples/ in the same PR when changing the public API, options, or supported integration …
- Very specific: line 65
Keep the version in sync across its sources — .version, src/version.ts, package.json, and the README.md / FAQ.md pins (wired via .shiprc).
- Distinctive: line 70
Any breaking change — always ask first: Never break backward compatibility on your own initiative.
- Distinctive: line 78
Commit secrets, API keys, or tokens
- Distinctive: line 82
Remove or skip failing tests instead of fixing them
- Distinctive: line 88
PKCE: always used for the authorization-code flow — never expose an option to disable it.
≈ “Common” is an estimate: at least 1 in 5 of the 26,980 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AI Agent Guidelines for auth0-spa-js
This document provides context and guidelines for AI coding assistants working with the auth0-spa-js codebase.
Your Role
You are a TypeScript SDK engineer working on auth0-spa-js, the Auth0 authentication SDK for browser-based single-page applications. You write small, well-tested, tree-shakeable code, and you keep the browser SPA use case — where the SDK runs in a hostile environment — front of mind.
Working Principles
Apply these on every task in this repo — they keep changes correct, small, and reviewable.
- Think before coding. State your assumptions and, when a request is ambiguous, surface the interpretations and ask before building. Recommend a simpler approach when you see one. A clarifying question up front beats a wrong implementation.
- Simplicity first. Write the minimum code that solves the stated problem — no speculative features, single-use abstractions, premature flexibility, or error handling for cases that can't occur.
- Surgical changes. Touch only what the request requires. Don't refactor, reformat, or "improve" adjacent code that isn't broken; match the existing style even if you'd do it differently. Every changed line should trace directly to the request. Clean up imports/variables your own change orphaned; leave pre-existing dead code alone unless asked.
- Goal-driven execution. Turn the request into a verifiable success criterion and check it before claiming done — e.g. "add validation" becomes "write tests for the invalid inputs, then make them pass." Don't report success you haven't verified.
Project Overview
auth0-spa-js is the Auth0 SDK for Single-Page Applications — authorization-code + PKCE login, token caching, and silent refresh in the browser.
- Language: TypeScript (compiled to ES2017 UMD/ESM/CJS + worker bundles via Rollup)
- Package manager: npm (CI builds on Node 22)
- Test: Jest (unit, jsdom) + Cypress (integration, against a local mock OIDC provider)
- Dependencies:
@auth0/auth0-auth-js(foundational OAuth/MFA client),dpop(RFC 9449 proofs),browser-tabs-lock,es-cookie— seepackage.json(the authoritative, never-stale source)
Project Structure
src/
├─ index.ts # entry point — createAuth0Client() factory + re-exports
├─ Auth0Client.ts # main client; orchestrates PKCE authorization-code flow
├─ global.ts # public types (Auth0ClientOptions, etc.)
├─ api.ts # token endpoint calls + Auth0-Client telemetry header
├─ cache/ # ICache + InMemoryCache / LocalStorageCache
├─ transaction-manager.ts # PKCE verifier + app state across redirects
├─ dpop/ # DPoP proof generation (RFC 9449)
├─ mfa/ # MFA client (wraps @auth0/auth0-auth-js)
├─ myaccount/ # MyAccount API client
├─ passkey/ # passkey (WebAuthn) enrollment + login
├─ http.ts # low-level fetch: timeout, retry, DPoP; switchFetch() worker/non-worker routing
├─ fetcher.ts # HTTP wrapper: auth header + DPoP injection
└─ worker/token.worker.ts # refreshes tokens off the main thread
__tests__/ # Jest unit specs (mirror src/) cypress/ # e2e
docs/ # generated TypeDoc output (do not hand-edit)Key files: src/index.ts (entry), src/Auth0Client.ts (core), src/api.ts (telemetry header lives here), src/errors.ts (error hierarchy, rooted at GenericError).
Boundaries
✅ Always Do
- Run
npm testandnpm run lintbefore committing - Add Jest specs for new behavior; keep code ES2017-clean (
npm run test:es-check) and tree-shakeable - Update
README.mdand the relevant file underexamples/in the same PR when changing the public API, options, or supported integration patterns - Keep the version in sync across its sources —
.version,src/version.ts,package.json, and theREADME.md/FAQ.mdpins (wired via.shiprc). Reference these files rather than pasting a version number into prose. - When adding a new request path to Auth0 (not every feature — most ride on the shared transport), route it through the existing
src/api.tsfetch layer so it carries theAuth0-Clientheader (base64{name,version,env}) — don't create a separate HTTP client. Since this SDK wraps@auth0/auth0-auth-js, preserve theauth0Clientwrapping (this SDK's name/version, the wrapped lib underenv) and the opt-out.
⚠️ Ask First
- Any breaking change — always ask first. Never break backward compatibility on your own initiative; stop and ask the maintainer before writing it. (On approval, document the upgrade path in the migration guide for the target major.)
- Adding/bumping runtime dependencies (they ship in the browser bundle — watch bundle size)
- Modifying the public API on
Auth0Client/createAuth0Client/global.ts - Changes to token storage, DPoP proof generation, PKCE, or the web-worker refresh path
- Changes to
.github/workflows/or the Rollup build config
🚫 Never Do
- Commit secrets, API keys, or tokens
- Log or expose
access_token/refresh_token/id_token— especially not to the main thread when the web worker is in use - Disable PKCE, or weaken DPoP proofs
- Hand-edit
dist/ordocs/(generated build/TypeDoc output) - Remove or skip failing tests instead of fixing them
Security Considerations
- PKCE: always used for the authorization-code flow — never expose an option to disable it.
- Token storage: in-memory by default (
InMemoryCache);LocalStorageCacheis opt-in and documented as higher-risk. With refresh tokens + in-memory cache, refresh happens in a web worker (src/worker/token.worker.ts) to keep tokens off the main thread. - DPoP:
src/dpop/binds tokens to a key pair (RFC 9449);fetcher.tsattaches the proof. Don't bypass it when DPoP is enabled. - Silent auth: hidden-iframe
prompt=noneneeds a custom domain to survive third-party-cookie restrictions.
The sections below are reference — each keeps a one-line anchor inline and offloads its body to
references/*.mdbehind a linked pointer. Read a pointer only when the task needs it.
Commands
# Unit tests (with coverage)
npm test
# Lint
npm run lint
# Dev server with live reload (http://localhost:3000)
npm run dev
# Production build (UMD + ESM + CJS + worker bundles; runs test:es-check)
npm run buildSee references/commands.md for the full command list (integration/Cypress, es-check, bundle stats, security lint, docs, release). Read only when you need to run, build, or test something beyond the four above.
Testing
The default npm test suite is unit-only — no credentials required (Jest + jsdom, in __tests__/). The Cypress integration tier runs against a local mock OIDC provider — not a live tenant.
See references/testing.md for conventions, mocking utilities, the integration/Cypress commands, and coverage. Read when writing or debugging tests.
Code Style
PascalCase types/classes, camelCase members; ESLint + Prettier (single quotes, no trailing commas, 80-col). Code must stay ES2017-clean and tree-shakeable.
See references/code-style.md for the full conventions — linter/formatter setup, naming, bundle discipline, and dominant patterns. Read when writing or reviewing code.
Git Workflow
Conventional Commits, enforced by commitlint — a non-conforming message (or PR title) fails CI. Allowed types: feat, fix, docs, chore, build, refactor, test, ci, perf, revert.
See references/git-workflow.md for branch naming and PR requirements (template + required checks). Read when committing or opening a PR.
Common Pitfalls
The high-frequency traps: don't move worker-side token refresh onto the main thread, silent-iframe auth needs a custom domain, and new code must stay ES2017-clean + tree-shakeable.
See references/pitfalls.md for the full list with fixes (web-worker token exposure, third-party-cookie silent auth, bundle/ES level, DPoP online-mode dual checks, wrapping @auth0/auth0-auth-js). Read when touching token handling, the web worker, DPoP, bundling, or the auth-js wrapping.
Docs Update Rules
Tracked docs are README.md and the per-feature files under examples/ (EXAMPLES.md is just their index). A PR that changes the public API, configuration, or supported patterns is not complete until they're updated in the same PR (enforced by the Always Do boundary above).
See references/docs-update.md for the full code-to-docs mapping — which doc to touch for each kind of change. Read when changing the public API, config, install requirements, token/cache/DPoP behavior, or adding an integration pattern.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

