Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • GoTrueApi

Index

Constructors

  • new GoTrueApi(__namedParameters: { cookieOptions?: CookieOptions; fetch?: ((input: RequestInfo | URL, init?: RequestInit) => Promise<Response>); headers?: {}; url: string }): GoTrueApi
  • Parameters

    • __namedParameters: { cookieOptions?: CookieOptions; fetch?: ((input: RequestInfo | URL, init?: RequestInit) => Promise<Response>); headers?: {}; url: string }
      • Optional cookieOptions?: CookieOptions
      • Optional fetch?: ((input: RequestInfo | URL, init?: RequestInit) => Promise<Response>)
          • (input: RequestInfo | URL, init?: RequestInit): Promise<Response>
          • Parameters

            • input: RequestInfo | URL
            • Optional init: RequestInit

            Returns Promise<Response>

      • Optional headers?: {}
        • [key: string]: string
      • url: string

    Returns GoTrueApi

Properties

_createRequestHeaders: any

Create a temporary object with all configured headers and adds the Authorization token to be used on request methods

param jwt

A valid, logged-in JWT.

cookieName: any
cookieOptions: CookieOptions
fetch: ((input: RequestInfo | URL, init?: RequestInit) => Promise<Response>)

Type declaration

    • (input: RequestInfo | URL, init?: RequestInit): Promise<Response>
    • Parameters

      • input: RequestInfo | URL
      • Optional init: RequestInit

      Returns Promise<Response>

headers: {}

Type declaration

  • [key: string]: string
url: string

Methods

  • Creates a new user.

    This function should only be called on a server. Never expose your service_role key in the browser.

    Parameters

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

  • deleteAuthCookie(req: any, res: any, options: { redirectTo?: string }): any
  • Deletes the Auth Cookies and redirects to the

    Parameters

    • req: any

      The request object.

    • res: any

      The response object.

    • options: { redirectTo?: string }

      Optionally specify a redirectTo URL in the options.

      • Optional redirectTo?: string

    Returns any

  • Delete a user. Requires a service_role key.

    This function should only be called on a server. Never expose your service_role key in the browser.

    Parameters

    • uid: string

      The user uid you want to remove.

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

  • generateLink(type: "signup" | "invite" | "magiclink" | "recovery" | "email_change_current" | "email_change_new", email: string, options?: { data?: object; password?: string; redirectTo?: string }): Promise<{ data: null | AuthSession | AuthUser; error: null | ApiError }>
  • Generates links to be sent via email or other.

    Parameters

    • type: "signup" | "invite" | "magiclink" | "recovery" | "email_change_current" | "email_change_new"

      The link type ("signup" or "magiclink" or "recovery" or "invite").

    • email: string

      The user's email.

    • Optional options: { data?: object; password?: string; redirectTo?: string }
      • Optional data?: object
      • Optional password?: string
      • Optional redirectTo?: string

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

  • getAuthCookieString(req: any, res: any): string[]
  • Helper method to generate the Auth Cookie string for you in case you can't use setAuthCookie.

    Parameters

    • req: any

      The request object.

    • res: any

      The response object.

    Returns string[]

    The Cookie string that needs to be set as the value for the Set-Cookie header.

  • getUrlForProvider(provider: Provider, options: { queryParams?: {}; redirectTo?: string; scopes?: string }): string
  • Generates the relevant login URL for a third-party provider.

    Parameters

    • provider: Provider

      One of the providers supported by GoTrue.

    • options: { queryParams?: {}; redirectTo?: string; scopes?: string }
      • Optional queryParams?: {}
        • [key: string]: string
      • Optional redirectTo?: string
      • Optional scopes?: string

    Returns string

  • Gets the current user details.

    This method is called by the GoTrueClient update where the jwt is set to this.currentSession.access_token and therefore, acts like getting the currently authenticated user

    Parameters

    • jwt: string

      A valid, logged-in JWT. Typically, the access_token for the currentSession

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

  • getUserByCookie(req: any, res?: any): Promise<{ data: null | AuthUser; error: null | ApiError; token: null | string; user: null | AuthUser }>
  • Get user by reading the cookie from the request. Works for Next.js & Express (requires cookie-parser middleware).

    Parameters

    • req: any
    • Optional res: any

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

  • getUserById(uid: string): Promise<{ data: null; error: ApiError } | { data: AuthUser; error: null }>
  • Get user by id.

    Parameters

    • uid: string

      The user's unique identifier

      This function should only be called on a server. Never expose your service_role key in the browser.

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

  • inviteUserByEmail(email: string, options?: { data?: object; redirectTo?: string }): Promise<{ data: null | AuthUser; error: null | ApiError }>
  • Sends an invite link to an email address.

    Parameters

    • email: string

      The email address of the user.

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

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

  • listUsers(): Promise<{ data: null; error: ApiError } | { data: AuthUser[]; error: null }>
  • Get a list of users.

    This function should only be called on a server. Never expose your service_role key in the browser.

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

  • refreshAccessToken(refreshToken: string): Promise<{ data: null | AuthSession; error: null | ApiError }>
  • Generates a new JWT.

    Parameters

    • refreshToken: string

      A valid refresh token that was returned on login.

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

  • resetPasswordForEmail(email: string, options?: { captchaToken?: string; redirectTo?: string }): Promise<{ data: null | {}; error: null | ApiError }>
  • Sends a reset request to an email address.

    Parameters

    • email: string

      The email address of the user.

    • Optional options: { captchaToken?: string; redirectTo?: string }
      • Optional captchaToken?: string
      • Optional redirectTo?: string

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

  • sendMagicLinkEmail(email: string, options?: { captchaToken?: string; redirectTo?: string; shouldCreateUser?: boolean }): Promise<{ data: null | {}; error: null | ApiError }>
  • Sends a magic login link to an email address.

    Parameters

    • email: string

      The email address of the user.

    • Optional options: { captchaToken?: string; redirectTo?: string; shouldCreateUser?: boolean }
      • Optional captchaToken?: string
      • Optional redirectTo?: string
      • Optional shouldCreateUser?: boolean

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

  • sendMobileOTP(phone: string, options?: { captchaToken?: string; shouldCreateUser?: boolean }): Promise<{ data: null | {}; error: null | ApiError }>
  • Sends a mobile OTP via SMS. Will register the account if it doesn't already exist

    Parameters

    • phone: string

      The user's phone number WITH international prefix

    • Optional options: { captchaToken?: string; shouldCreateUser?: boolean }
      • Optional captchaToken?: string
      • Optional shouldCreateUser?: boolean

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

  • setAuthCookie(req: any, res: any): void
  • Set/delete the auth cookie based on the AuthChangeEvent. Works for Next.js & Express (requires cookie-parser middleware).

    Parameters

    • req: any

      The request object.

    • res: any

      The response object.

    Returns void

  • signInWithEmail(email: string, password: string, options?: { captchaToken?: string; redirectTo?: string }): Promise<{ data: null | AuthSession; error: null | ApiError }>
  • Logs in an existing user using their email address.

    Parameters

    • email: string

      The email address of the user.

    • password: string

      The password of the user.

    • Optional options: { captchaToken?: string; redirectTo?: string }
      • Optional captchaToken?: string
      • Optional redirectTo?: string

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

  • Logs in an OpenID Connect user using their id_token.

    Parameters

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

  • signInWithPhone(phone: string, password: string, options?: { captchaToken?: string }): Promise<{ data: null | AuthSession; error: null | ApiError }>
  • Logs in an existing user using their phone number and password.

    Parameters

    • phone: string

      The phone number of the user.

    • password: string

      The password of the user.

    • Optional options: { captchaToken?: string }
      • Optional captchaToken?: string

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

  • signOut(jwt: string): Promise<{ error: null | ApiError }>
  • Removes a logged-in session.

    Parameters

    • jwt: string

      A valid, logged-in JWT.

    Returns Promise<{ error: null | ApiError }>

  • signUpWithEmail(email: string, password: string, options?: { captchaToken?: string; data?: object; redirectTo?: string }): Promise<{ data: null | AuthSession | AuthUser; error: null | ApiError }>
  • Creates a new user using their email address.

    Parameters

    • email: string

      The email address of the user.

    • password: string

      The password of the user.

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

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

    A logged-in session if the server has "autoconfirm" ON

  • signUpWithPhone(phone: string, password: string, options?: { captchaToken?: string; data?: object }): Promise<{ data: null | AuthSession | AuthUser; error: null | ApiError }>
  • Signs up a new user using their phone number and a password.

    Parameters

    • phone: string

      The phone number of the user.

    • password: string

      The password of the user.

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

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

  • Updates the user data.

    Parameters

    • jwt: string

      A valid, logged-in JWT.

    • attributes: UserAttributes

      The data you want to update.

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

  • Updates the user data.

    Parameters

    • uid: string
    • attributes: AdminUserAttributes

      The data you want to update.

      This function should only be called on a server. Never expose your service_role key in the browser.

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

  • verifyMobileOTP(phone: string, token: string, options?: { redirectTo?: string }): Promise<{ data: null | AuthSession | AuthUser; error: null | ApiError }>
  • deprecated

    Use verifyOTP instead!

    Parameters

    • phone: string

      The user's phone number WITH international prefix

    • token: string

      token that user was sent to their mobile phone

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

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

  • Send User supplied Email / Mobile OTP to be verified

    Parameters

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

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

Generated using TypeDoc