Skip to content

Documentation / react-auth / PrivyEvents

Interface: PrivyEvents

Properties

accessToken

accessToken: Object

Type declaration

onAccessTokenGranted

onAccessTokenGranted: (accessToken) => void

Callback that will execute when a user's access token is granted.

Parameters

accessToken: string

The user's access token

Returns

void

onAccessTokenRemoved

onAccessTokenRemoved: () => void

Callback that will execute when a user's access token is removed.

Returns

void


configureMfa

configureMfa: Object

Type declaration

onMfaRequired

onMfaRequired: (mfaMethods) => void

Callback that will execute when MFA is required to complete a given action.

Parameters

mfaMethods: ("sms" | "totp" | "passkey")[]

[] - List of MFA methods that the user can choose from

Returns

void


connectWallet

connectWallet: Object

Type declaration

onError?

onError?: (error) => void

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

Parameters

error: PrivyErrorCode

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

Returns

void

onSuccess?

onSuccess?: (wallet) => void

Callback that will execute once a successful connectWallet completes. This will not run in the case of a wallet-based authentication or link flow.

Parameters

wallet: BaseConnectedEthereumWallet | BaseConnectedSolanaWallet

[BaseConnectedEthereumWallet | BaseConnectedSolanaWallet]([object Object]) the wallet object correspending to the connection

Returns

void


createWallet

createWallet: Object

Type declaration

onError?

onError?: (error) => void

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

Parameters

error: PrivyErrorCode

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

Returns

void

onSuccess?

onSuccess?: (wallet) => void

Callback that will execute once on a successful embedded wallet creation. This will run when createWallet is called manually, or when config.embeddedWallets.createOnLogin triggers an automatic wallet creation.

Parameters

wallet: Wallet

BaseConnectedWallet- the created wallet object

Returns

void


customAuth

customAuth: Object

Type declaration

onAuthenticated

onAuthenticated: (o) => void

Callback that will execute when Privy successfully exchanges a custom auth JWT for a Privy JWT

Parameters

o: Object

o.user: User

The Privy user

Returns

void

onUnauthenticated

onUnauthenticated: () => void

Callback that will execute when Privy detects a user is logged out from the third-party auth system, and correspondingly logs the user out.

Returns

void


fundSolanaWallet

fundSolanaWallet: Object

Type declaration

onUserExited?

onUserExited?: (o) => void

Callback that will execute when a funding flow is exited. This fires when a user closes a funding flow modal, for any reason.

Parameters

o: Object

o.address: string

o.balance: undefined | bigint

o.cluster: SolanaCluster

o.fundingMethod: null | FundingMethod | "manual"

Returns

void


fundWallet

fundWallet: Object

Type declaration

onUserExited?

onUserExited?: (o) => void

Callback that will execute when a funding flow is exited. This fires when a user closes a funding flow modal, for any reason.

Parameters

o: Object

o.address: string

o.balance: undefined | bigint

o.chain: Chain

o.fundingMethod: null | FundingMethod | "manual"

Returns

void


linkAccount

linkAccount: Object

Type declaration

onError?

onError?: (error, details) => void

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

Parameters

error: PrivyErrorCode

{PrivyErrorCode} - the corresponding error code

details: Object

details.linkMethod: LoginMethod

{LoginMethod} - the type of (attempted) linked account

Returns

void

onSuccess?

onSuccess?: (user, linkMethod, linkedAccount) => void

Callback that will execute once on a successful linking of a new account/login method. This will run when any of the 'link' methods are called manually.

Parameters

user: User

User- the user the account was linked to

linkMethod: LoginMethod

[LoginMethod]([object Object])- the type of linked account

linkedAccount: LinkedAccountWithMetadata

the newly linked account

Returns

void


login

login: Object

Type declaration

onComplete?

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.
Parameters

user: User

User the user oject corresponding to the authenticated user

isNewUser: boolean

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

wasAlreadyAuthenticated: boolean

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

loginMethod: null | LoginMethod

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

loginAccount: null | LinkedAccountWithMetadata

the account corresponding to the loginMethod used

Returns

void

onError?

onError?: (error) => void

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

Parameters

error: PrivyErrorCode

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

Returns

void

onOAuthLoginComplete?

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.

Parameters

oAuthTokens: OAuthTokens

OAuthTokens - the OAuth tokens returned from the OAuth provider

Returns

void


logout

logout: Object

Type declaration

onSuccess?

onSuccess?: () => void

Callback that will execute when a user successfully logs out.

Returns

void


oAuthAuthorization

oAuthAuthorization: Object

Type declaration

onOAuthTokenGrant

onOAuthTokenGrant: (oAuthTokens, o) => void

Callback that will execute when a user successfully authorizes an OAuth flow.

Parameters

oAuthTokens: OAuthTokens

OAuthTokens - the OAuth tokens returned from the OAuth provider:

o: Object

o.user: User

User (optional) The list of OAuth scopes the access token is approved for.

Returns

void


sendSolanaTransaction

sendSolanaTransaction: Object

Type declaration

onError?

onError?: (error) => void

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

Parameters

error: PrivyErrorCode

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

Returns

void

onSuccess?

onSuccess?: (response) => void

Callback that will execute once a successful sendSolanaTransaction completes. This will not run in the case of a wallet-based authentication or link flow.

Parameters

response: SolanaTransactionReceipt

the response SolanaTransactionReceipt from the successful transaction

Returns

void


sendTransaction

sendTransaction: Object

Type declaration

onError?

onError?: (error) => void

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

Parameters

error: PrivyErrorCode

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

Returns

void

onSuccess?

onSuccess?: (response) => void

Callback that will execute once a successful sendTransaction completes. This will not run in the case of a wallet-based authentication or link flow.

Parameters

response: TransactionResponse

the response (type TransactionResponse https://docs.ethers.org/v5/api/providers/types/#providers-TransactionResponse) from the successful transaction

Returns

void


setWalletPassword

setWalletPassword: Object

Type declaration

onError?

onError?: (error) => void

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

Parameters

error: PrivyErrorCode

{PrivyErrorCode} - the corresponding error code

Returns

void

onSuccess?

onSuccess?: (wallet) => void

Callback that will execute once a successful setWalletPassword completes.

Parameters

wallet: Wallet

Wallet- the wallet object that the password was set for

Returns

void


setWalletRecovery

setWalletRecovery: Object

Type declaration

onError?

onError?: (error) => void

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

Parameters

error: PrivyErrorCode

{PrivyErrorCode} - the corresponding error code

Returns

void

onSuccess?

onSuccess?: (method, wallet) => void

Callback that will execute once a successful setWalletRecovery completes.

Parameters

method: UserRecoveryMethod

wallet: Wallet

Wallet- the walle]et object that the recovery was set for

Returns

void


signMessage

signMessage: Object

Type declaration

onError?

onError?: (error) => void

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

Parameters

error: PrivyErrorCode

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

Returns

void

onSuccess?

onSuccess?: (signature) => void

Callback that will execute once a successful signMessage completes. This will not run in the case of a wallet-based authentication or link flow.

Parameters

signature: string

the signature (type string) of the embedded wallet used to sign message

Returns

void


signTypedData

signTypedData: Object

Type declaration

onError?

onError?: (error) => void

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

Parameters

error: PrivyErrorCode

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

Returns

void

onSuccess?

onSuccess?: (signature) => void

Callback that will execute once a successful signTypedData completes.

Parameters

signature: string

the signature (type string) of the embedded wallet used to sign

Returns

void


update

update: Object

Type declaration

onError?

onError?: (error, details) => void

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

Parameters

error: PrivyErrorCode

{PrivyErrorCode} - the corresponding error code

details: Object

details.linkMethod: LoginMethod

{LoginMethod} - the type of (attempted) linked account

Returns

void

onSuccess?

onSuccess?: (user, updateMethod, updatedAccount) => void

Callback that will execute once on a successful updating of an account. This will run when any of the 'updateAccount' methods are called manually.

Parameters

user: User

User- the user the account was linked to

updateMethod: LoginMethod

[LoginMethod]([object Object])- the type of updated account

updatedAccount: LinkedAccountWithMetadata

the newly updated account

Returns

void