Skip to main content

Interface: PrivyInterface

Allows you to manage the user's current authentication state and access their linked accounts. You can access the fields and methods documented here via the usePrivy hook.

Properties

authenticated

authenticated: boolean

True if the user is authenticated, false otherwise.

You should always check that ready is true before using this value. Otherwise, the value may outdated while the Privy client fetches fresh tokens.


forkSession

forkSession: () => Promise<string>

Type declaration

▸ (): Promise<string>

Get a short-lived, one-time-use token to start a new Privy session from the existing authenticated session. Raises an exception if the current session was already forked from a previous session.

Returns

Promise<string>


getAccessToken

getAccessToken: () => Promise<null | string>

Type declaration

▸ (): Promise<null | string>

Get the Privy access token (JWT) for an authenticated user. Returns null for an unauthenticated user.

You may use this token to authorize requests sent from your frontend, and can validate it in your backend against your app's Privy verification key.

This will automatically attempt to refresh the session if the token is expired or about to expire.

Returns

Promise<null | string>


getEthereumProvider

getEthereumProvider: () => EIP1193Provider

Type declaration

▸ (): EIP1193Provider

Get an EIP-1193-compatible provider from the user's wallet, if the user has connected one.

You may then use the Ethereum Javascript API syntax to send JSON-RPC requests to the user's wallet.

Returns

EIP1193Provider


getEthersProvider

getEthersProvider: () => Web3Provider

Type declaration

▸ (): Web3Provider

Get an ethers.js-compatible provider from the user's wallet, if the user has connected one.

Returns

Web3Provider


getWeb3jsProvider

getWeb3jsProvider: () => AbstractProvider

Type declaration

▸ (): AbstractProvider

Get a web3.js-compatible provider from the user's wallet, if the user has connected one.

Returns

AbstractProvider


linkDiscord

linkDiscord: () => void

Type declaration

▸ (): void

For users who are authenticated, prompts the user to link Discord OAuth account This will directly initiate the OAuth flow for Discord.

Returns

void


linkEmail

linkEmail: () => void

Type declaration

▸ (): void

For users who are authenticated, opens the Privy modal and prompts the user to link an email. This will open the Privy Modal which will guide the user through this action.

Returns

void


linkGithub

linkGithub: () => void

Type declaration

▸ (): void

For users who are authenticated, prompts the user to link Github OAuth account This will directly initiate the OAuth flow for Github.

Returns

void


linkGoogle

linkGoogle: () => void

Type declaration

▸ (): void

For users who are authenticated, prompts the user to link a Google OAuth account. This will directly initiate the OAuth flow for Google.

Returns

void


linkPhone

linkPhone: () => void

Type declaration

▸ (): void

For users who are authenticated, opens the Privy modal and prompts the user to link a phone number. This will open the Privy Modal which will guide the user through this action.

Returns

void


linkTwitter

linkTwitter: () => void

Type declaration

▸ (): void

For users who are authenticated, prompts the user to link a Twitter OAuth account This will directly initiate the OAuth flow for Twitter.

Returns

void


linkWallet

linkWallet: () => void

Type declaration

▸ (): void

For users who are authenticated, opens the Privy modal and prompts the user to link a wallet. This will open the Privy Modal which will guide the user through this action.

Returns

void


login

login: () => void

Type declaration

▸ (): void

Opens the Privy login modal and prompts the user to login.

Returns

void


logout

logout: () => Promise<void>

Type declaration

▸ (): Promise<void>

Log the current user out and clears their authentication state. authenticated will become false, user will become null, and the Privy Auth tokens will be deleted from the browser's local storage.

You may await this call to take an action once logout is complete (e.g. redirecting to a specific page).

Returns

Promise<void>


ready

ready: boolean

Check whether the PrivyProvider is ready to be used. You should wait for this to be true before using values such as authenticated and user.


setActiveWallet

setActiveWallet: (address: string) => void

Type declaration

▸ (address): void

Set one of the authenticated wallet addresses (part of user.linkedAccounts with type 'wallet'). as the active wallet. If you pass a wallet that's not one of the linkedAccounts, this will throw an error.

The active wallet will be the one that getEthersProvider() will use as a signer (used for signing & transactions). It is also the wallet present at user.wallet, and that value is updated when this is called.

Note that when you link a new wallet, it becomes 'active' by default.

Parameters
NameType
addressstring
Returns

void


unlinkDiscord

unlinkDiscord: (subject: string) => Promise<User>

Type declaration

▸ (subject): Promise<User>

Unlink a Discord social account from a user, by passing the discord subject ID. Note that you can only unlink a social account if the user has at least one other account.

Parameters
NameType
subjectstring
Returns

Promise<User>


unlinkEmail

unlinkEmail: (address: string) => Promise<User>

Type declaration

▸ (address): Promise<User>

Unlink an email account from a user, by passing the email address. Note that you can only unlink an email account if the user has at least one other account.

Parameters
NameType
addressstring
Returns

Promise<User>


unlinkGithub

unlinkGithub: (subject: string) => Promise<User>

Type declaration

▸ (subject): Promise<User>

Unlink a Github social account from a user, by passing the github subject ID. Note that you can only unlink a social account if the user has at least one other account.

Parameters
NameType
subjectstring
Returns

Promise<User>


unlinkGoogle

unlinkGoogle: (subject: string) => Promise<User>

Type declaration

▸ (subject): Promise<User>

Unlink a Google social account from a user, by passing the google subject ID. Note that you can only unlink a social account if the user has at least one other account.

Parameters
NameType
subjectstring
Returns

Promise<User>


unlinkPhone

unlinkPhone: (phoneNumber: string) => Promise<User>

Type declaration

▸ (phoneNumber): Promise<User>

Unlink a phone account from a user, by passing the phone number. Note that you can only unlink a phone account if the user has at least one other account.

Parameters
NameType
phoneNumberstring
Returns

Promise<User>


unlinkTwitter

unlinkTwitter: (subject: string) => Promise<User>

Type declaration

▸ (subject): Promise<User>

Unlink a Twitter social account from a user, by passing the twitter subject ID. Note that you can only unlink a social account if the user has at least one other account.

Parameters
NameType
subjectstring
Returns

Promise<User>


unlinkWallet

unlinkWallet: (address: string) => Promise<User>

Type declaration

▸ (address): Promise<User>

Unlink a wallet account from a user, by passing the public address. Note that you can only unlink a wallet account if the user has at least one other account.

Parameters
NameType
addressstring
Returns

Promise<User>


user

user: null | User

The user object, or null if the user is not authenticated.


walletConnector

walletConnector: null | PrivyConnector

Get the PrivyConnector object This shouldn't need to be used directly unless creating a plugin, like a WAGMI plugin