Handling the user object
All of Privy’s login methods result in a unified JSON representation of your user.
To get the current user, inspect the user
object returned by the usePrivy
hook:
Unauthenticated users
For unauthenticated users, the user
object will be null
.
Authenticated users
For authenticated users, you can use the following fields:
The user’s Privy DID, which you may use to identify your user on your backend
The custom metadata set for a given user
You can set custom metadata for a user via Privy’s backend server SDK and/or API endpoints.
The user
object also contains information about all of the accounts a user has linked with Privy:
If a user has not linked an account of a given type, the corresponding field on the user
object will be undefined.
Different account types contain different information about the underlying account. For example, you might use user.wallet.address
to get a user’s Ethereum address and user.discord.username
to get a user’s Discord username. Check out the SDK Reference to see what data each type contains.
Alternatively, you can also get a list of all the accounts a user has linked with Privy via user.linkedAccounts
. Each account in this list is additionally annotated with a type
field that denotes the type of account (‘email’, ‘phone’, ‘wallet’, etc.).
Users can have multiple passkeys linked to their account. To find all linked
passkeys, use the linkedAccounts
list and filter by passkey
account type.
Below is an example of how you might use the user
object in a minimal user profile:
Refreshing the user
object
In order to update a user
object after any type of backend update, (i.e. unlinking an account or setting custom metadata) you can ensure the user object in the application is up-to-date by invoking the refreshUser
method from the useUser
hook:
Was this page helpful?