Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • GoTrueClient

Index

Constructors

  • new GoTrueClient(options: { autoRefreshToken?: boolean; cookieOptions?: CookieOptions; detectSessionInUrl?: boolean; fetch?: ((input: RequestInfo | URL, init?: RequestInit) => Promise<Response>); headers?: {}; localStorage?: PromisifyMethods<Pick<Storage, "getItem" | "removeItem" | "setItem">>; multiTab?: boolean; persistSession?: boolean; url?: string }): GoTrueClient
  • Create a new client for use in the browser.

    Parameters

    • options: { autoRefreshToken?: boolean; cookieOptions?: CookieOptions; detectSessionInUrl?: boolean; fetch?: ((input: RequestInfo | URL, init?: RequestInit) => Promise<Response>); headers?: {}; localStorage?: PromisifyMethods<Pick<Storage, "getItem" | "removeItem" | "setItem">>; multiTab?: boolean; persistSession?: boolean; url?: string }
      • Optional autoRefreshToken?: boolean

        Set to "true" if you want to automatically refresh the token before expiring.

      • Optional cookieOptions?: CookieOptions
      • Optional detectSessionInUrl?: boolean

        Set to "true" if you want to automatically detects OAuth grants in the URL and signs in the user.

      • Optional fetch?: ((input: RequestInfo | URL, init?: RequestInit) => Promise<Response>)
          • (input: RequestInfo | URL, init?: RequestInit): Promise<Response>
          • A custom fetch implementation.

            Parameters

            • input: RequestInfo | URL
            • Optional init: RequestInit

            Returns Promise<Response>

      • Optional headers?: {}

        Any additional headers to send to the GoTrue server.

        • [key: string]: string
      • Optional localStorage?: PromisifyMethods<Pick<Storage, "getItem" | "removeItem" | "setItem">>

        Provide your own local storage implementation to use instead of the browser's local storage.

      • Optional multiTab?: boolean

        Set to "false" if you want to disable multi-tab/window events.

      • Optional persistSession?: boolean

        Set to "true" if you want to automatically save the user session into local storage.

      • Optional url?: string

        The URL of the GoTrue server.

    Returns GoTrueClient

Properties

_callRefreshToken: any
_handleEmailSignIn: any
_handleOpenIDConnectSignIn: any
_handlePhoneSignIn: any
_handleProviderSignIn: any
_handleVisibilityChange: any
_listenForMultiTabEvents: any

Listens for changes to LocalStorage and updates the current session.

_notifyAllSubscribers: any
_persistSession: any
_recoverAndRefresh: any

Recovers the session from LocalStorage and refreshes Note: this method is async to accommodate for AsyncStorage e.g. in React native.

_recoverSession: any

Attempts to get the session from LocalStorage Note: this should never be async (even for React Native), as we need it to return immediately in the constructor.

_removeSession: any
_saveSession: any

set currentSession and currentUser process to _startAutoRefreshToken if possible

_startAutoRefreshToken: any

Clear and re-create refresh token timer

param value

time intervals in milliseconds

api: GoTrueApi

Namespace for the GoTrue API methods. These can be used for example to get a user from a JWT in a server environment or reset a user's password.

autoRefreshToken: boolean
currentSession: null | AuthSession

The session object for the currently logged in user or null.

currentUser: null | AuthUser

The currently logged in user or null.

localStorage: PromisifyMethods<Pick<Storage, "getItem" | "removeItem" | "setItem">>
multiTab: boolean
networkRetries: number
persistSession: boolean
refreshTokenTimer?: Timeout
stateChangeEmitters: Map<string, Subscription>

Methods

  • getSessionFromUrl(options?: { storeSession?: boolean }): Promise<{ data: null | AuthSession; error: null | ApiError }>
  • Gets the session data from a URL string

    Parameters

    • Optional options: { storeSession?: boolean }
      • Optional storeSession?: boolean

        Optionally store the session in the browser

    Returns Promise<{ data: null | AuthSession; error: null | ApiError }>

  • Force refreshes the session including the user data in case it was updated in a different session.

    Returns Promise<{ data: null | AuthSession; error: null | ApiError; user: null | AuthUser }>

  • Returns the session data, if there is an active session.

    Returns null | AuthSession

  • Overrides the JWT on the current client. The JWT will then be sent in all subsequent network requests.

    Parameters

    • access_token: string

      a jwt access token

    Returns AuthSession

  • setSession(refresh_token: string): Promise<{ error: null | ApiError; session: null | AuthSession }>
  • Sets the session data from refresh_token and returns current Session and Error

    Parameters

    • refresh_token: string

      a JWT token

    Returns Promise<{ error: null | ApiError; session: null | AuthSession }>

  • signIn(__namedParameters: UserCredentials, options?: { captchaToken?: string; queryParams?: {}; redirectTo?: string; scopes?: string; shouldCreateUser?: boolean }): Promise<{ error: null | ApiError; provider?: Provider; session: null | AuthSession; url?: null | string; user: null | AuthUser }>
  • Log in an existing user, or login via a third-party provider.

    Parameters

    • __namedParameters: UserCredentials
    • Optional options: { captchaToken?: string; queryParams?: {}; redirectTo?: string; scopes?: string; shouldCreateUser?: boolean }
      • Optional captchaToken?: string
      • Optional queryParams?: {}
        • [key: string]: string
      • Optional redirectTo?: string
      • Optional scopes?: string
      • Optional shouldCreateUser?: boolean

    Returns Promise<{ error: null | ApiError; provider?: Provider; session: null | AuthSession; url?: null | string; user: null | AuthUser }>

  • signOut(): Promise<{ error: null | ApiError }>
  • Inside a browser context, signOut() will remove the logged in user from the browser session and log them out - removing all items from localstorage and then trigger a "SIGNED_OUT" event.

    For server-side management, you can revoke all refresh tokens for a user by passing a user's JWT through to auth.api.signOut(JWT: string). There is no way to revoke a user's session JWT before it automatically expires

    Returns Promise<{ error: null | ApiError }>

  • Creates a new user.

    Parameters

    • __namedParameters: UserCredentials
    • Optional options: { captchaToken?: string; data?: object; redirectTo?: string }
      • Optional captchaToken?: string
      • Optional data?: object
      • Optional redirectTo?: string

    Returns Promise<{ error: null | ApiError; session: null | AuthSession; user: null | AuthUser }>

  • Updates user data, if there is a logged in user.

    Parameters

    Returns Promise<{ data: null | AuthUser; error: null | ApiError; user: null | AuthUser }>

  • Inside a browser context, user() will return the user data, if there is a logged in user.

    For server-side management, you can get a user through auth.api.getUserByCookie()

    Returns null | AuthUser

  • Log in a user given a User supplied OTP received via mobile.

    Parameters

    • params: VerifyOTPParams
    • Optional options: { redirectTo?: string }
      • Optional redirectTo?: string

    Returns Promise<{ error: null | ApiError; session: null | AuthSession; user: null | AuthUser }>

Generated using TypeDoc