
auth0-spa-js
Use when adding Auth0 login or token management to a Vanilla JS, Svelte, or framework-agnostic SPA. Integrates @auth0/auth0-spa-js — use when there is no framework-specific Auth0 SDK available.
- Installs
- 434
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/auth0/agent-skills --skill auth0-spa-js- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads auth0-spa-js automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
Auth0 SPA JS Integration
Add authentication to any browser-based single-page application using @auth0/auth0-spa-js — the low-level Auth0 SDK for Vanilla JS, Svelte, SolidJS, and any SPA not using React, Angular, or Vue.
Agent instruction: Before providing SDK setup instructions, fetch the latest release version by running:
gh api repos/auth0/auth0-spa-js/releases/latest --jq '.tag_name'Use the returned version in all dependency lines instead of any hardcoded version below. If the command fails, fall back to checking https://github.com/auth0/auth0-spa-js/releases.
Prerequisites
- Modern browser with ES2017+ support
- npm or yarn (or use CDN for no-bundler apps)
- Auth0 account with a Single Page Application configured
- If you don't have Auth0 set up, see auth0-quickstart
When NOT to Use
- React SPAs (hooks, Auth0Provider): Use auth0-react
- Angular SPAs (AuthModule, AuthGuard): Use auth0-angular
- Vue 3 SPAs (createAuth0, useAuth0): Use auth0-vue
- Next.js (server-side sessions, App Router): Use auth0-nextjs
- Nuxt (server-side SSR): Use auth0-nuxt
- Express server-side web apps: Use auth0-express
- React Native / Expo mobile apps: Use auth0-react-native
Quick Start Workflow
1. Install SDK
npm install @auth0/auth0-spa-js
Or via CDN (no bundler). Run this to get the latest version, then use it in your HTML:
VERSION=$(npm view @auth0/auth0-spa-js version)
<script src="https://cdn.auth0.com/js/auth0-spa-js/$VERSION/auth0-spa-js.production.js"></script>
2. Configure Auth0
For automated setup with Auth0 CLI, see Setup Guide for complete scripts.
For manual setup, create .env (Vite):
VITE_AUTH0_DOMAIN=your-tenant.auth0.com
VITE_AUTH0_CLIENT_ID=your-client-id
In Auth0 Dashboard, set for your Single Page Application:
- Allowed Callback URLs:
http://localhost:5173 - Allowed Logout URLs:
http://localhost:5173 - Allowed Web Origins:
http://localhost:5173
3. Initialize Auth0 Client
import { createAuth0Client } from '@auth0/auth0-spa-js';
const auth0 = await createAuth0Client({
domain: import.meta.env.VITE_AUTH0_DOMAIN,
clientId: import.meta.env.VITE_AUTH0_CLIENT_ID,
authorizationParams: {
redirect_uri: window.location.origin
}
});
// Handle redirect callback after login
const query = new URLSearchParams(window.location.search);
if ((query.has('code') || query.has('error')) && query.has('state')) {
await auth0.handleRedirectCallback();
window.history.replaceState({}, document.title, window.location.pathname);
}
4. Add Login / Logout
Agent instruction: Before adding new UI elements, search the project for existing click handlers for login, logout, sign-in, or sign-out buttons. If existing handlers are found, hook the Auth0 code into them without modifying the existing UI. Only create new buttons if no existing handlers are found.
// Login
document.getElementById('login-btn').addEventListener('click', async () => {
await auth0.loginWithRedirect();
});
// Logout
document.getElementById('logout-btn').addEventListener('click', () => {
auth0.logout({
logoutParams: { returnTo: window.location.origin }
});
});
// Update UI based on auth state
const isAuthenticated = await auth0.isAuthenticated();
if (isAuthenticated) {
const user = await auth0.getUser();
console.log(user.name, user.email);
}
5. Get Access Tokens for API Calls
const accessToken = await auth0.getTokenSilently();
const response = await fetch('https://your-api.example.com/data', {
headers: { Authorization: `Bearer ${accessToken}` }
});
6. Build & Verify
Agent instruction: After completing the integration, build the project to verify it compiles successfully:
npm run buildIf the build fails, analyze the error output and fix the issues. Common integration build failures include:
- Module not found: Missing
npm install @auth0/auth0-spa-js— run the install command- Cannot find name 'import.meta': TypeScript target too low — set
"target": "ES2020"or higher intsconfig.jsoncreateAuth0Clientis not a function: Wrong import path or CDN usage without bundle step- Env vars undefined at runtime: Vite requires
VITE_prefix; webpack/CRA requiresREACT_APP_prefixRe-run the build after each fix. Track the number of build-fix iterations.
Failcheck: If the build still fails after 5–6 fix attempts, stop and ask the user using
AskUserQuestion: "The build is still failing after several fix attempts. How would you like to proceed?"
- Let the skill continue fixing iteratively — continue the build-fix loop for another 5–6 attempts
- Fix it manually — show the remaining errors and let the user resolve them
- Skip build verification — proceed without a successful build
Detailed Documentation
- Setup Guide — Automated setup scripts (Bash/PowerShell), Auth0 CLI commands,
.envconfiguration, callback URL setup - Integration Patterns — Token management, calling APIs, refresh tokens, organizations, MFA, DPoP, error handling, advanced patterns
- Testing & Reference — Configuration options, claims reference, testing checklist, common issues, security considerations
Common Mistakes
| Mistake | Fix |
|---|---|
Callback URL port mismatch (e.g., localhost:3001 vs localhost:5173) | Match Allowed Callback URLs exactly to your dev server port in Auth0 Dashboard |
client_secret in SPA code | SPAs must never have a client secret — remove it. Auth0 sets auth method to None for SPA apps |
Tokens stored in localStorage | Use in-memory storage (default) or sessionStorage. Never localStorage — XSS risk |
getTokenSilently() throws login_required on page refresh | Add your app origin to Allowed Web Origins in Auth0 Dashboard |
handleRedirectCallback() not called after redirect | Must call after login redirect to exchange the auth code; without this the URL params persist and re-trigger |
Domain includes https:// prefix | Auth0 domain should be hostname only: your-tenant.auth0.com, not https://your-tenant.auth0.com |
loginWithPopup() called from async init code | Popups must be triggered directly from a user gesture (click handler). Never call from init or page load code |
Using Auth0Provider from @auth0/auth0-react in Vanilla JS | For Vanilla JS, use createAuth0Client() directly — no provider component needed |
Related Skills
- auth0-quickstart — Set up an Auth0 account and application
- auth0-react — Auth0 for React SPAs with hooks
- auth0-angular — Auth0 for Angular SPAs
- auth0-vue — Auth0 for Vue 3 SPAs
- auth0-mfa — Add Multi-Factor Authentication
- auth0-cli — Manage Auth0 resources from the terminal
Quick Reference
Core Methods
| Method | Description |
|---|---|
createAuth0Client(options) | Create and initialize client (calls checkSession internally) |
new Auth0Client(options) | Instantiate without auto session check |
auth0.loginWithRedirect(options?) | Redirect to Auth0 Universal Login |
auth0.loginWithPopup(options?) | Open Auth0 login in a popup |
auth0.logout(options?) | Clear session and redirect |
auth0.handleRedirectCallback(url?) | Process redirect result after login |
auth0.isAuthenticated() | Promise<boolean> |
auth0.getUser() | Promise<User | undefined> |
auth0.getTokenSilently(options?) | Promise<string> — access token |
auth0.checkSession() | Attempt silent re-authentication |
Common Use Cases
- Login/Logout → See Step 4 above
- Protecting content → Integration Guide
- API calls with tokens → Integration Guide
- Refresh tokens → Integration Guide
- Organizations → Integration Guide
- MFA handling → Integration Guide
- Error handling → Integration Guide
References
FAQ
What does the auth0-spa-js skill do?
Use when adding Auth0 login or token management to a Vanilla JS, Svelte, or framework-agnostic SPA. Integrates @auth0/auth0-spa-js — use when there is no framework-specific Auth0 SDK available.
How do I install auth0-spa-js?
Run npx skills add https://github.com/auth0/agent-skills --skill auth0-spa-js in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/auth0-spa-js/ (personal) or .claude/skills/auth0-spa-js/ (project).
Which AI agents can use auth0-spa-js?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is auth0-spa-js safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains auth0-spa-js?
It is published by auth0 in auth0/agent-skills, and it is an official skill from the maker of the technology it covers. It has 434 recorded installs.
More from auth0/agent-skills
auth0
auth0/agent-skills
Use when adding, fixing, or improving how an app authenticates users or protects an API, or when using or configuring any Auth0 feature — signing users in and out, sessions and tokens, guarding routes and endpoints, MFA, passwordless passkey login (WebAuthn), SSO, Organizations, RBAC, custom domains, Universal Portals for hosted account and organization self-service, or Universal Login branding. Also use to audit a tenant's health, security, and plan fit (CheckMate), to debug why an auth flow fails, to migrate from another auth provider, or to set up the Vercel native integration. Covers any web, mobile, or backend framework and every Auth0 SDK, tool, and API. Use even if the user never mentions Auth0.
auth0-quickstart
auth0/agent-skills
Use when adding Auth0 authentication to any app and unsure which SDK or skill to use. Detects the project's framework and routes to the right setup workflow — use this as the entry point even if the user just says "add login to my app" or "set up Auth0" without naming a framework.
auth0-nextjs
auth0/agent-skills
Use when adding Auth0 login, logout, protected pages, or middleware to a Next.js application. Supports App Router and Pages Router with @auth0/nextjs-auth0 — use even if the user says "add login to my Next.js app" or "protect my Next.js routes".
auth0-react
auth0/agent-skills
Use when adding Auth0 login, logout, protected routes, or user sessions to a React SPA. Integrates @auth0/auth0-react — use even if the user says "add login to my React app" or "protect my React routes" without naming the SDK.
auth0-react-native
auth0/agent-skills
Use when adding Auth0 login, logout, or biometric auth to a bare React Native app (not Expo). Integrates react-native-auth0 with native deep linking.
auth0-express
auth0/agent-skills
Use when adding session-based login, logout, or protected routes to an Express.js web application. Integrates express-openid-connect — use even if the user says "add login to my Express app" or "protect my Express routes".
Popular frontend & design skills
setup-matt-pocock-skills
mattpocock/skills
Configure this repo for the engineering skills: set up its issue tracker, triage label vocabulary, and domain doc layout. Run once before first use of the other engineering skills.
frontend-design
anthropics/skills
Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.
hyperframes-animation
heygen-com/hyperframes
All animation knowledge for HyperFrames — atomic motion rules, multi-phase scene blueprints, scene transitions, broader motion-design techniques, AND the seven runtime adapters (GSAP default, plus Lottie, Three.js, Anime.js, CSS keyframes, Web Animations API, TypeGPU). Use for any motion or animation task: pick 2-4 rules and compose, or load a blueprint, or look up runtime-specific API (e.g. GSAP eases / Lottie player / Three.js mixer). Also covers auditing an existing composition's choreography (animation map) and 24 named text-animation effects. HyperFrames-native: single paused timeline, seek-safe, deterministic.
prototype
mattpocock/skills
Build a throwaway prototype to answer a design question. Use when the user wants to sanity-check whether a state model or logic feels right, or explore what a UI should look like.
hyperframes-core
heygen-com/hyperframes
The HyperFrames composition contract — build one renderable project. Use for composition structure, the data- timing attributes, class="clip", tracks, sub-compositions, variables, framework-owned media playback, deterministic-render rules, and validation. Read before writing composition HTML.
vercel-react-best-practices
vercel-labs/agent-skills
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.