Skip to content

Documentation / react-auth / useLogin

Function: useLogin()

useLogin(callbacks?): Object

Use this hook to log the user in, and to attach callbacks for successful logins, already-authenticated users, and login errors.

Parameters

callbacks?: Object

callbacks.onComplete?: (user, isNewUser, wasAlreadyAuthenticated, loginMethod, loginAccount) => void

Callback that will execute once a login flow successfully completes.

  • If config.embeddedWallets.createOnLogin is set to 'off' or a wallet creation flow is not applicable, this will run after the user successfully authenticates.
  • If config.embeddedWallets.createOnLogin is set to 'users-without-wallets' or 'all-users', this will run after the user successfully authenticates and creates their wallet (if applicable).
  • If a user is already authenticated, this will run immediately and the wasAlreadyAuthenticated flag will be set to true.

ParamUser the user oject corresponding to the authenticated user

Param {boolean} boolean flag indicating if this is the user's first time logging in to your app

Param {boolean} - boolean flag indicating whether the user entered the application already authenticated

Param {string} - the method used by the user to login

Param the account corresponding to the loginMethod used

callbacks.onError?: (error) => void

Callback that will execute in the case of a non-successful login.

Param [PrivyErrorCode]([object Object]) - the corresponding error code

callbacks.onOAuthLoginComplete?: (oAuthTokens) => void

Callback that will execute once a successful OAuth login flow completes. This will only run in the case of an OAuth login flow.

This will always be called before onComplete in the case of an OAuth login flow. If you will be doing anything after the user is logged in (e.g. sending data to your API or redirecting to an authenticated route), you should wait for onComplete to run.

ParamOAuthTokens - the OAuth tokens returned from the OAuth provider

Returns

Object

login - opens the Privy modal and prompts the user to login

login

login: (options?) => void

Parameters

options?: MouseEvent<any, any> | RuntimeLoginOverridableOptions

Returns

void