Skip to main content

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:
  1. Your application redirects to Auth0’s /authorize endpoint with prompt=none
  2. Auth0 checks for an active session without showing the login page
  3. If a session exists, Auth0 redirects back with tokens
  4. 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 the prompt=none query parameter to the login URL:
This is the simplest approach and works with the built-in /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 is login_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

All of these errors indicate that silent authentication cannot proceed and interactive authentication is required.

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
iframe-based silent authentication may not work if cookies are blocked by the browser’s privacy settings. Consider using alternative session refresh strategies.

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 alongside prompt: '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
Ensure your cookies are configured securely:
lib/auth0.ts
Always use secure cookies in production. Silent authentication will fail if cookies are not properly configured.

Troubleshooting

Silent Authentication Always Fails

Possible causes:
  1. Third-party cookies blocked: Modern browsers block third-party cookies by default
  2. No active Auth0 session: User has never logged in or session expired
  3. Wrong domain: Auth0 domain doesn’t match the configured domain
  4. Configuration issues: Missing or incorrect authorization parameters
Solutions:

iframe Not Working

Problem: Silent authentication in iframe doesn’t complete Solution: Check CSP (Content Security Policy) headers and frame-ancestors:
middleware.ts

Further Reading