Prerequisites
Create Passport Client
Set up your Passport client in Immutable Hub to get the credentials needed for authentication.Create Passport Client
Step-by-step guide to creating a Passport client, configuring redirect URIs, and getting your Client ID
- Client ID from your Passport client in Hub
- Publishable Key from your Hub project settings
Passport Credentials Reference
| Field | Type | Description |
|---|---|---|
| Client ID | Provided by Hub | Unique identifier for your application. Copy from Hub and use in SDK initialization. |
| Publishable Key | Provided by Hub | Public key safe for client-side code. Copy from Hub project settings. |
| Application Type | You configure | Select Web for TypeScript/web apps, Native for Unity/Unreal games. |
| Application Name | You configure | Identifier for your project inside Passport (e.g., “My Game”). |
| Redirect URIs | You configure | Where users land after successful authentication. Must exactly match redirectUri in your code. Examples: http://localhost:3000/redirect (web), mygame://callback (native). |
| Logout URIs | You configure | Where users land after logout. Must exactly match logoutRedirectUri in your code. Examples: http://localhost:3000/logout (web), mygame://logout (native). |
Passport uses OpenID Connect (OIDC). Redirect URIs must be exact matches—wildcards aren’t supported for security reasons. Register multiple URIs for different environments (localhost, staging, production).
Installation
Install the Immutable SDK for your platform to get started with Passport:TypeScript
Install via npm or yarn
Next.js
Install via npm for App Router
Unity
Install via Package Manager
Unreal
Install Passport plugin in your Unreal project
Initialize Passport
- Next.js
- TypeScript
- Unity
- Unreal
Create your auth configuration:Create the API route handler:Wrap your app with Set environment variables:For full setup details including server utilities and route protection, see the Next.js integration guide.
SessionProvider:Login
- Next.js
- TypeScript
- Unity
- Unreal
The
useLogin hook provides embedded, popup, and redirect login flows. All functions accept an optional config; when omitted, sandbox defaults are used.Embedded Login
Shows an in-page modal for login method selection — no popup window required:Popup Login
Redirect Login
Direct Login Options
Skip the login method selection screen and go directly to a specific provider:| Option | Description |
|---|---|
directLoginMethod | The authentication provider (email, google, or apple) |
email | Required when directLoginMethod is email |
marketingConsentStatus | Marketing consent (OptedIn or Unsubscribed) |
Handle the Callback
On your redirect URI page, process the authentication callback:- Next.js
- React
- Vanilla JS
CallbackPage component handles both redirect and popup flows automatically. For popup logins, it communicates tokens back to the parent window and closes itself.Get User Information
User Profile
- Next.js
- TypeScript
- Unity
- Unreal
Session Management
Check If Logged In
- Next.js
- TypeScript
- Unity
- Unreal
Always use
isAuthenticated from useImmutableSession to determine if a user is logged in.isAuthenticated validates all of the following:- NextAuth reports
'authenticated'status - The session object exists
- A valid access token is present in the session
- No session-level error exists (such as
RefreshTokenError)
getUser(true)), isAuthenticated remains true if the user was previously authenticated, preventing UI flicker.Get Access Token
For authenticated API calls to your backend:- Next.js
- TypeScript
- Unreal
getAccessToken() returns a guaranteed-fresh access token. If the current token is valid it returns immediately; if expired, it triggers a server-side refresh and blocks until the fresh token is available. Multiple concurrent calls share a single refresh request.SWR Fetcher
Event Handler
Periodic Polling
Token Refresh
Automatic Refresh
The server-side JWT callback automatically refreshes tokens when the access token expires. This happens transparently during any session access.Force Refresh
After operations that update user claims on the identity provider (such as zkEVM wallet registration), force a token refresh to get the updated data:Get ID Token
The ID token contains user identity claims:- Next.js
- TypeScript
- Unreal
The ID token is not stored in the session cookie (to stay within CDN header size limits). Use
getUser() to access it — the client persists it in localStorage automatically.Logout
- Next.js
- TypeScript
- Unity
- Unreal
The To customize the logout redirect URI:
useLogout hook performs federated logout — it clears both the local NextAuth session and the upstream Immutable/Auth0 session by redirecting to the logout endpoint. This is important when using social logins like Google: without federated logout, the auth server caches the social session, so users clicking “Login” again would be automatically logged in with the same account instead of being prompted to choose.Error Handling
Common Logout Issues:| Error | Cause | Solution |
|---|---|---|
| Logout callback timeout | Silent logout page didn’t load | Verify logoutRedirectUri is accessible |
| Wallet still connected | Cleanup order wrong | Disconnect wallet before passport.logout() |
| Session persists (Unreal) | Soft logout used | Set DoHardLogout: true |
Backend JWT Validation
Validate Passport JWTs on your server to secure API endpoints.Node.js with jose
Express Middleware
JWT Claims Reference
| Claim | Type | Description |
|---|---|---|
sub | string | Unique Passport user ID |
iss | string | Always https://auth.immutable.com/ |
aud | string | Your audience (e.g., platform_api) |
exp | number | Expiration timestamp |
iat | number | Issued at timestamp |
email | string | User’s email (if scope granted) |
email_verified | boolean | Whether email is verified |
Error Handling
Handle authentication errors gracefully to provide better user experience:- Next.js
- TypeScript
Check the session
error field for token-level issues and use try/catch around getAccessToken():| Session Error | Description | Action |
|---|---|---|
"TokenExpired" | Access token expired | Handled automatically by getAccessToken() |
"RefreshTokenError" | Refresh token invalid | Prompt user to sign in again |
Common Error Types
| Error Type | Description | Recommended Action |
|---|---|---|
AUTHENTICATION_ERROR | Login or authentication failed | Ask user to try again or use different provider |
USER_REGISTRATION_ERROR | User registration failed | Check if user already exists or retry |
WALLET_CONNECTION_ERROR | Failed to connect wallet | Retry connection or check network |
INVALID_CONFIGURATION | Invalid Passport configuration | Verify clientId and redirectUri |