Skip to main content
This Quickstart is currently in Beta. We’d love to hear your feedback!

AI Prompt

Using AI to integrate Auth0? Add this prompt to Cursor, Windsurf, Copilot, Claude Code or your favourite AI-powered IDE to speed up development.
Prerequisites: Before you begin, ensure you have the following installed:Svelte Version Compatibility: This quickstart works with Svelte 5.x and newer.

Get Started

This quickstart demonstrates how to add Auth0 authentication to a Svelte application. You’ll build a secure single-page app with login, logout, and user profile features using the Auth0 SPA JS SDK.
1

Create a new project

Create a new Svelte project for this Quickstart
Open the project
2

Install the Auth0 SPA SDK

3

Setup your Auth0 App

Next up, you need to create a new app on your Auth0 tenant and add the environment variables to your project.You have three options to set up your Auth0 app: use the Quick Setup tool (recommended), run a CLI command, or configure manually via the Dashboard:
4

Create the Auth0 store

Create the store file
Add the following code to manage authentication state
src/lib/stores/auth.ts
5

Create Login, Logout and Profile Components

Create component files
And add the following code snippets
6

Run your app

CheckpointYou should now have a fully functional Auth0 login page running on your localhost

Troubleshooting

If clicking the login button does nothing:
  1. Open browser DevTools (F12) and check the Console tab
  2. Verify .env file has real Auth0 credentials
  3. Check that Auth0 application has correct callback URLs configured
  4. Ensure VITE_AUTH0_DOMAIN is just the domain (e.g., tenant.auth0.com) without https://
“Callback URL mismatch”:
  • Go to Auth0 Dashboard → Applications → Your App → Settings
  • Add http://localhost:5173 to Allowed Callback URLs, Allowed Logout URLs, and Allowed Web Origins
  • Click “Save Changes”
“Invalid state”:
  • Clear browser cache and cookies
  • Try in an incognito/private window
If npm run dev fails:
  • Run npm run check to see TypeScript errors
  • Verify all files were created correctly
  • Check that all dependencies are installed: npm install
Still stuck? Check the Auth0 Community or SvelteKit Discord for help.