Overview
Aurora uses Auth.js (NextAuth.js) for session management. Logout is handled entirely on the client side through Auth.js, and does not require a backend API endpoint.Client-Side Logout
To log out a user, use the Auth.jssignOut function:
Full Example
What Happens During Logout
- Session Cleared: Auth.js clears the session from cookies/storage
- Token Invalidated: The session token is removed
- Client State Reset: User authentication state is cleared
- Redirect (optional): User is redirected to the specified URL
Session Cleanup
Auth.js automatically handles:- Clearing session cookies
- Removing JWT tokens
- Invalidating the session on the server
- Broadcasting logout to all tabs (if configured)
API Integration
After logout:- The
X-User-IDheader will no longer be sent with requests - API endpoints requiring authentication will return
401 Unauthorized - User must log in again to access protected resources
Security Considerations
Client-Side Logout
While logout is client-side, the session token is invalidated and cannot be reused.Session Expiration
Sessions automatically expire based on Auth.js configuration. Default settings:- Session Max Age: 30 days (configurable)
- Idle Timeout: Session expires after inactivity period
Multiple Devices
Logging out on one device does not automatically log out other devices. To implement global logout:- Store session IDs in the database
- Invalidate all sessions on logout
- Check session validity on each request
Example: Logout with Confirmation
Troubleshooting
Logout Not Working
If logout fails to clear the session:- Check Auth.js configuration in
app/api/auth/[...nextauth]/route.ts - Verify cookies are being cleared in browser DevTools
- Ensure the callback URL is allowed in Auth.js config
- Check for errors in the browser console
Session Persists After Logout
If the session persists:- Clear browser cookies manually
- Check for custom session storage logic
- Verify Auth.js session callbacks are configured correctly
Related Documentation
Login
Authenticate users
Authentication Overview
Learn about authentication