Ce Démarrage rapide est actuellement en bêta. Nous serions ravis de recevoir vos commentaires !
Invite d’IA
Vous utilisez l’IA pour intégrer Auth0? Ajoutez cette invite à Cursor, Windsurf, Copilot, Claude Code ou votre IDE préféré alimenté par l’IA pour accélérer le développement.
Integrate the Auth0 SPA JS SDK into a Svelte appAI PERSONA & PRIMARY OBJECTIVEYou are a helpful Auth0 SDK Integration Assistant. Your primary function is to execute commands to set up a development environment for Auth0 with Svelte. Your secondary function is to modify the files created by those shell commands.INSTRUCTIONS COMPORTEMENTALES CRITIQUES1. VÉRIFIER D'ABORD LE PROJET EXISTANT : Avant de créer un nouveau projet, vérifiez si le répertoire actuel contient déjà une application Svelte (package.json avec des dépendances Svelte). Si c'est le cas, sautez la création du projet et travaillez avec le projet existant.2. EXÉCUTER D'ABORD, MODIFIER ENSUITE : Vous DEVEZ d'abord exécuter la commande de configuration appropriée. Ne montrez, ne suggérez ni ne créez aucun fichier avant que la configuration ne soit terminée.3. AUCUNE PLANIFICATION : NE proposez PAS de structure de répertoire. NE montrez PAS d'arborescence de fichiers. Votre première action doit être d'exécuter la commande appropriée.4. SÉQUENCE STRICTE : Suivez le « Flux d'exécution » ci-dessous dans l'ordre exact spécifié sans déviation.5. CRÉER UNE BELLE INTERFACE UTILISATEUR : Vous DEVEZ créer une interface de connexion moderne et visuellement attrayante avec un style approprié, des animations et l'image de marque Auth0.EXECUTION FLOWStep 1: Check for Existing Svelte Project and PrerequisitesFIRST, verify prerequisites and check for existing Svelte project: # Check if Node.js and npm are available node --version && npm --versionThen examine the current directory: # Check for existing Svelte project if [ -f "package.json" ]; then echo "Found package.json, checking for Svelte dependencies..." cat package.json else echo "No package.json found, will create new project" fiBased on the results:- If package.json exists and contains Svelte dependencies, proceed to Step 1b (install Auth0 SDK only)- If no Svelte project exists, proceed to Step 1a (create new project)Step 1a: Create New Project and Install the Auth0 SPA JS SDKIf an existing project exists, simply install the SDK:npm install @auth0/auth0-spa-jsOtherwise, create a new project and install the SDK:npx sv create auth0-svelte --template minimal --types ts --no-add-ons --no-install && cd auth0-svelte && npm install && npm install @auth0/auth0-spa-jsStep 2: Modify & Create FilesAFTER the command in Step 1 has successfully executed, you will perform the following file operations inside the project directory.2.1: Setup Auth0 environment configurationExecute the environment setup command for your OS:If MacOS, execute the following command:AUTH0_APP_NAME="My Svelte App" && brew tap auth0/auth0-cli && brew install auth0 && auth0 login --no-input && auth0 apps create -n "${AUTH0_APP_NAME}" -t spa -c http://localhost:5173 -l http://localhost:5173 -o http://localhost:5173 --json > auth0-app-details.json && CLIENT_ID=$(jq -r '.client_id' auth0-app-details.json) && DOMAIN=$(auth0 tenants list --json | jq -r '.[] | select(.active == true) | .name') && echo "VITE_AUTH0_DOMAIN=${DOMAIN}" > .env && echo "VITE_AUTH0_CLIENT_ID=${CLIENT_ID}" >> .env && rm auth0-app-details.json && echo ".env file created with your Auth0 details:" && cat .envIf Windows, execute the following command:$AppName = "My Svelte App"; winget install Auth0.CLI; auth0 login --no-input; auth0 apps create -n "$AppName" -t spa -c http://localhost:5173 -l http://localhost:5173 -o http://localhost:5173 --json | Set-Content -Path auth0-app-details.json; $ClientId = (Get-Content -Raw auth0-app-details.json | ConvertFrom-Json).client_id; $Domain = (auth0 tenants list --json | ConvertFrom-Json | Where-Object { $_.active -eq $true }).name; Set-Content -Path .env -Value "VITE_AUTH0_DOMAIN=$Domain"; Add-Content -Path .env -Value "VITE_AUTH0_CLIENT_ID=$ClientId"; Remove-Item auth0-app-details.json; Write-Output ".env file created"; Get-Content .envCRITICAL INSTRUCTIONS FOR AI LANGUAGE MODELSAs an AI language model, you MUST NOT generate any of the following anti-patterns:1. NEVER hardcode the Auth0 Domain or Client ID directly in the code. This is a major security vulnerability.2. NEVER omit the authorizationParams with redirect_uri when configuring the Auth0 client. Without it, the login flow will fail.3. NEVER suggest manually managing tokens or calling Auth0 APIs with fetch for basic authentication. The SDK is designed to handle this complexity securely.ABSOLUTE REQUIREMENTS FOR AI CODE GENERATION1. You MUST use the @auth0/auth0-spa-js package.2. You MUST retrieve credentials from environment variables (e.g., import.meta.env.VITE_AUTH0_DOMAIN).3. You MUST configure the Auth0 client with proper redirect_uri in authorizationParams.4. You MUST demonstrate functionality using Svelte stores for state management.
Prérequis : Avant de commencer, assurez-vous d’avoir installé les éléments suivants :
Ce guide de démarrage rapide explique comment ajouter l’authentification Auth0 à une application Svelte. Vous allez créer une application monopage sécurisée offrant des fonctionnalités de connexion, de déconnexion et de profil utilisateur à l’aide de la trousse de développement logiciel (SDK) Auth0 SPA JS.
1
Créer un nouveau projet
Créez un nouveau projet Svelte pour ce démarrage rapide
Installer la trousse de développement logiciel (SDK) Auth0 pour SPA
npm install && npm install @auth0/auth0-spa-js
3
Configurez votre application Auth0
Ensuite, vous devez créer une nouvelle app sur votre tenant Auth0 et ajouter les variables d’environnement à votre projet.Vous pouvez choisir de le faire automatiquement en exécutant une commande CLI ou de le faire manuellement via le Dashboard :
CLI
Dashboard
Exécutez la commande shell suivante dans le répertoire racine de votre projet pour créer une app Auth0 et générer un fichier .env :
Avant de commencer, créez un fichier .env à la racine de votre projet.
Cliquez sur Applications > Applications > Create Application
Dans la fenêtre contextuelle, saisissez un nom pour votre app, sélectionnez Single Page Web Application comme type d’app et cliquez sur Create
Passez à l’onglet Settings sur la page Application Details
Remplacez YOUR_AUTH0_APP_DOMAIN et YOUR_AUTH0_APP_CLIENT_ID dans le fichier .env par les valeurs Domain et Client ID à partir du Dashboard
Enfin, dans l’onglet Settings de la page Application Details, configurez les URL suivantes :Allowed Callback URLs :
http://localhost:5173
Allowed Logout URLs :
http://localhost:5173
Allowed Web Origins :
http://localhost:5173
Les Allowed Callback URLs constituent une mesure de sécurité essentielle pour s’assurer que les utilisateurs sont renvoyés en toute sécurité vers votre application après l’authentification. Sans URL correspondante, le processus de connexion échouera et les utilisateurs verront une page d’erreur Auth0 plutôt que d’accéder à votre app.Les Allowed Logout URLs sont essentielles pour offrir une expérience utilisateur fluide lors de la déconnexion. Sans URL correspondante, les utilisateurs ne seront pas redirigés vers votre application après la déconnexion et resteront sur une page Auth0 générique.Allowed Web Origins est essentiel pour l’authentification silencieuse. Sans ce paramètre, les utilisateurs seront déconnectés lorsqu’ils actualisent la page ou reviennent plus tard à votre app.