Skip to main content
Module

x/supabase/mod.ts>GoTrueClient

An isomorphic Javascript client for Supabase.
Go to Latest
class GoTrueClient
Re-export
import { GoTrueClient } from "https://deno.land/x/supabase@1.3.1/mod.ts";

Constructors

new
GoTrueClient(options: { url?: string; headers?: { [key: string]: string; }; detectSessionInUrl?: boolean; autoRefreshToken?: boolean; persistSession?: boolean; localStorage?: Storage; cookieOptions?: CookieOptions; })

Create a new client for use in the browser.

Properties

protected
autoRefreshToken: boolean
protected
currentSession: Session | null

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

protected
currentUser: User | null

The currently logged in user or null.

protected
localStorage: SupportedStorage
protected
persistSession: boolean
protected
optional
refreshTokenTimer: ReturnType<setTimeout>
protected
stateChangeEmitters: Map<string, Subscription>

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.

Methods

private
_callRefreshToken(refresh_token?)
private
_handleEmailSignIn(
email: string,
password: string,
options?: { redirectTo?: string; },
)
private
_handlePhoneSignIn(phone: string, password: string)
private
_handleProviderSignIn(provider: Provider, options?: { redirectTo?: string; scopes?: string; })
private
_persistSession(currentSession: Session)

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

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
_saveSession(session: Session)

set currentSession and currentUser process to _startAutoRefreshToken if possible

private
_startAutoRefreshToken(value: number)

Clear and re-create refresh token timer

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

Gets the session data from a URL string

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

Receive a notification every time an auth event happens.

refreshSession(): Promise<{ data: Session | null; user: User | null; error: ApiError | null; }>

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

session(): Session | null

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

setAuth(access_token: string): Session

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

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

Sets the session data from refresh_token and returns current Session and Error

signIn(unnamed 0: UserCredentials, options?: { redirectTo?: string; scopes?: string; }): Promise<{ session: Session | null; user: User | null; provider?: Provider; url?: string | null; error: ApiError | null; data: Session | null; }>

Log in an existing user, or login via a third-party provider.

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

Inside a browser context, signOut() will remove extract 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 disable sessions by passing a JWT through to auth.api.signOut(JWT: string)

signUp(unnamed 0: UserCredentials, options?: { redirectTo?: string; data?: Record<string, unknown>; }): Promise<{ user: User | null; session: Session | null; error: ApiError | null; data: Session | User | null; }>

Creates a new user.

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

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

user(): User | null

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()

verifyOTP(unnamed 0: VerifyOTPParams, options?: { redirectTo?: string; }): Promise<{ user: User | null; session: Session | null; error: ApiError | null; data: Session | User | null; }>

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