# GoTrueClient | @supabase/supabase-js
Documentation for @supabase/supabase-js

### Hierarchy

- GoTrueClient

## Index

### Constructors

- constructor

### Properties

- _callRefreshToken
- _handleEmailSignIn
- _handleOpenIDConnectSignIn
- _handlePhoneSignIn
- _handleProviderSignIn
- _handleVisibilityChange
- _listenForMultiTabEvents
- _notifyAllSubscribers
- _persistSession
- _recoverAndRefresh
- _recoverSession
- _removeSession
- _saveSession
- _startAutoRefreshToken
- api
- autoRefreshToken
- currentSession
- currentUser
- localStorage
- multiTab
- networkRetries
- persistSession
- refreshTokenTimer
- stateChangeEmitters

### Methods

- getSessionFromUrl
- onAuthStateChange
- refreshSession
- session
- setAuth
- setSession
- signIn
- signOut
- signUp
- update
- user
- verifyOTP

## Constructors

### constructor

- 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

- - Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:37

  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

### Private _callRefreshToken

_callRefreshToken: any

- Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:190

### Private _handleEmailSignIn

_handleEmailSignIn: any

- Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:176

### Private _handleOpenIDConnectSignIn

_handleOpenIDConnectSignIn: any

- Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:179

### Private _handlePhoneSignIn

_handlePhoneSignIn: any

- Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:177

### Private _handleProviderSignIn

_handleProviderSignIn: any

- Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:178

### Private _handleVisibilityChange

_handleVisibilityChange: any

- Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:208

### Private _listenForMultiTabEvents

_listenForMultiTabEvents: any

- Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:207

Listens for changes to LocalStorage and updates the current session.

### Private _notifyAllSubscribers

_notifyAllSubscribers: any

- Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:191

### Private _persistSession

_persistSession: any

- Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:197

### Private _recoverAndRefresh

_recoverAndRefresh: any

- Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:189

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

### Private _recoverSession

_recoverSession: any

- Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:184

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.

### Private _removeSession

_removeSession: any

- Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:198

### Private _saveSession

_saveSession: any

- Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:196

set currentSession and currentUser process to _startAutoRefreshToken if possible

### Private _startAutoRefreshToken

_startAutoRefreshToken: any

- Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:203

Clear and re-create refresh token timer

param value

  time intervals in milliseconds

### api

api: GoTrueApi

- Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:9

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.

### Protected autoRefreshToken

autoRefreshToken: boolean

- Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:18

### Protected currentSession

currentSession: null | AuthSession

- Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:17

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

### Protected currentUser

currentUser: null | AuthUser

- Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:13

The currently logged in user or null.

### Protected localStorage

localStorage: PromisifyMethods<Pick<Storage, "getItem" | "removeItem" | "setItem">>

- Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:20

### Protected multiTab

multiTab: boolean

- Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:21

### Protected networkRetries

networkRetries: number

- Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:24

### Protected persistSession

persistSession: boolean

- Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:19

### Protected Optional refreshTokenTimer

refreshTokenTimer?: Timeout

- Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:23

### Protected stateChangeEmitters

stateChangeEmitters: Map<string, Subscription >

- Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:22

## Methods

### getSessionFromUrl

- getSessionFromUrl(options?: { storeSession?: boolean }): Promise<{ data: null | AuthSession ; error: null | ApiError }>

- - Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:153

  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 }>

### onAuthStateChange

- onAuthStateChange(callback: ((event: AuthChangeEvent, session: null | AuthSession ) => void)): { data: null | Subscription ; error: null | ApiError }

- - Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:172

  Receive a notification every time an auth event happens.

  #### Parameters

  - ##### callback: ((event: AuthChangeEvent, session: null | AuthSession ) => void)

    - - (event: AuthChangeEvent, session: null | AuthSession ): void

      - #### Parameters

        - ##### event: AuthChangeEvent

        - ##### session: null | AuthSession

        #### Returns void

  #### Returns { data: null | Subscription ; error: null | ApiError }

  A subscription object which can be used to unsubscribe itself.

  - ##### data: null | Subscription

  - ##### error: null | ApiError

### refreshSession

- refreshSession(): Promise<{ data: null | AuthSession ; error: null | ApiError ; user: null | AuthUser }>

- - Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:123

  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 }>

### session

- session(): null | AuthSession

- - Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:119

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

  #### Returns null | AuthSession

### setAuth

- setAuth(access_token: string): AuthSession

- - Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:148

  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

- setSession(refresh_token: string): Promise<{ error: null | ApiError ; session: null | AuthSession }>

- - Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:140

  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

- 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 }>

- - Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:80

  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

- signOut(): Promise<{ error: null | ApiError }>

- - Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:165

  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 }>

### signUp

- signUp(__namedParameters: UserCredentials, options?: { captchaToken?: string; data?: object; redirectTo?: string }): Promise<{ error: null | ApiError ; session: null | AuthSession ; user: null | AuthUser }>

- - Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:59

  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 }>

### update

- update(attributes: UserAttributes ): Promise<{ data: null | AuthUser ; error: null | ApiError ; user: null | AuthUser }>

- - Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:131

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

  #### Parameters

  - ##### attributes: UserAttributes

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

### user

- user(): null | AuthUser

- - Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:115

  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

### verifyOTP

- verifyOTP(params: VerifyOTPParams, options?: { redirectTo?: string }): Promise<{ error: null | ApiError ; session: null | AuthSession ; user: null | AuthUser }>

- - Defined in node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.d.ts:103

  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