Overview
Silent authentication checks for an existing Auth0 session without user interaction. This is useful for seamlessly logging users back in when they return to your application, or for checking authentication status without redirecting to the login page.Silent authentication uses the
prompt: 'none' authorization parameter to perform authentication without displaying the Auth0 login page.How It Works
When you initiate silent authentication:- Your application redirects to Auth0’s
/authorizeendpoint withprompt=none - Auth0 checks for an active session without showing the login page
- If a session exists, Auth0 redirects back with tokens
- If no session exists, Auth0 returns an error (typically
login_required)
Implementation Methods
There are two ways to implement silent authentication:Method 1: Using Query Parameters (Simplest)
Add theprompt=none query parameter to the login URL:
/auth/login route.
Method 2: Custom Route (More Control)
Create a custom route for more control over the authentication flow:1
Create a custom silent auth route
app/api/auth/silent/route.ts
2
Use the custom route
Error Handling
Auth0 returns specific errors when silent authentication fails. The most common islogin_required, which occurs when no active session exists.
Client-Side Error Handling
app/components/SilentAuth.tsx
Server-Side Error Handling
Handle silent authentication errors in a custom route:app/api/auth/silent/route.ts
Common Error Codes
Use Cases
Single Sign-On (SSO) Experience
Automatically log users in if they have an active session:app/page.tsx
Session Refresh Without Interruption
Refresh the user’s session without showing the login page:app/components/SessionRefresh.tsx
Check Authentication Status
Check if a user has an active Auth0 session:app/components/AuthCheck.tsx
Best Practices
1. Fallback to Interactive Login
Always provide a fallback to interactive login when silent authentication fails:2. Handle Privacy Settings
Modern browsers may block third-party cookies, which can prevent silent authentication from working. Inform users and provide alternative options:3. Avoid Infinite Loops
Be careful not to create infinite redirect loops:4. Use Appropriate Timeouts
Set reasonable timeouts for silent authentication attempts:Configuration Options
You can pass additional authorization parameters alongsideprompt: 'none':
Security Considerations
Cross-Site Request Forgery (CSRF)
Silent authentication uses the same CSRF protections as interactive login:- State parameter is automatically generated and verified
- Transaction cookies are used to maintain flow state
- PKCE (Proof Key for Code Exchange) is used by default
Cookie Security
Ensure your cookies are configured securely:lib/auth0.ts
Troubleshooting
Silent Authentication Always Fails
Possible causes:- Third-party cookies blocked: Modern browsers block third-party cookies by default
- No active Auth0 session: User has never logged in or session expired
- Wrong domain: Auth0 domain doesn’t match the configured domain
- Configuration issues: Missing or incorrect authorization parameters
iframe Not Working
Problem: Silent authentication in iframe doesn’t complete Solution: Check CSP (Content Security Policy) headers and frame-ancestors:middleware.ts