Public-facing Auth class for authentication Provides login/logout helpers and exposes auth state events

Constructors

  • Create a new Auth instance

    Parameters

    Returns Auth

    import { Auth } from '@imtbl/auth';

    const auth = new Auth({
    authenticationDomain: 'https://auth.immutable.com',
    passportDomain: 'https://passport.immutable.com',
    clientId: 'your-client-id',
    redirectUri: 'https://your-app.com/callback',
    scope: 'openid profile email transact',
    });

Properties

Event emitter for authentication events (LOGGED_IN, LOGGED_OUT) Exposed for wallet and passport packages to subscribe to auth state changes

Methods

  • Login the user with extended options Supports cached sessions, silent login, redirect flow, and direct login

    Parameters

    Returns Promise<null | User>

    Promise that resolves with the user or null

  • Login with redirect Redirects the page for authentication

    Parameters

    Returns Promise<void>

    Promise that resolves when redirect is initiated

  • Login callback handler Call this in your redirect or popup callback page

    Returns Promise<undefined | User>

    Promise that resolves with the authenticated user or undefined (for popup flows)

  • Logout the current user

    Returns Promise<void>

    Promise that resolves when logout is complete

  • Get the current authenticated user

    Returns Promise<null | User>

    Promise that resolves with the user or null if not authenticated

  • Get the current authenticated user or initiate login if needed

    Returns Promise<User>

    Promise that resolves with an authenticated user

  • Get the current authenticated zkEVM user

    Returns Promise<UserZkEvm>

    Promise that resolves with a zkEVM-capable user

  • Get the ID token for the current user

    Returns Promise<undefined | string>

    Promise that resolves with the ID token or undefined

  • Get the access token for the current user

    Returns Promise<undefined | string>

    Promise that resolves with the access token or undefined

  • Check if user is logged in

    Returns Promise<boolean>

    Promise that resolves with true if user is logged in

  • Force a silent user refresh (for silent login)

    Returns Promise<null | User>

    Promise that resolves with the user or null if refresh fails

  • Trigger a background user refresh without awaiting the result

    Returns void

  • Get the PKCE authorization URL for login flow

    Parameters

    • OptionaldirectLoginOptions: auth.DirectLoginOptions

      Optional direct login options

    • OptionalimPassportTraceId: string

      Optional trace ID for tracking

    Returns Promise<string>

    Promise that resolves with the authorization URL

  • Handle the PKCE login callback

    Parameters

    • authorizationCode: string

      The authorization code from the OAuth provider

    • state: string

      The state parameter for CSRF protection

    Returns Promise<User>

    Promise that resolves with the authenticated user

  • Store tokens from device flow and retrieve user

    Parameters

    Returns Promise<User>

    Promise that resolves with the authenticated user

  • Get the logout URL

    Returns Promise<undefined | string>

    Promise that resolves with the logout URL or undefined if not available

  • Handle the silent logout callback

    Parameters

    • url: string

      The URL containing logout information

    Returns Promise<void>

    Promise that resolves when callback is handled

  • Get the configured OIDC client ID

    Returns Promise<string>

    Promise that resolves with the client ID string