Authentication state
Throughout your app, you may want to gate certain user experiences based on whether the current user is authenticated or not. Privy makes it easy to check your user’s authentication status and handle it appropriately.
You can use the boolean authenticated
from the usePrivy
hook to determine if your user is authenticated or not.
Before determining a user’s auth status from Privy, you should verify that
Privy has fully initialized and is ready
Usage
You can use the boolean authenticated
from the usePrivy
hook to determine if your user is authenticated or not.
Before determining a user’s auth status from Privy, you should verify that
Privy has fully initialized and is ready
Usage
You can use the user
object from the usePrivy
hook to determine if your user is authenticated or not.
Usage
You can use the authState
property from the Privy
client to determine if your user is authenticated or not.
Auth state is exposed as a Publisher on the Privy object:
There are various ways to determine user’s auth state, outlined below:
1. Directly grab the User
As a convenience, you can grab the user object directly from the Privy instance. If the user is not null, there is an authenticated user.
2. Grab the user’s current auth state
3. Subscribe to auth state updates
You can use the authState
property from the Privy
client to determine if your user is authenticated or not.
Auth state is exposed as a StateFlow on the Privy object:
Usage
There are various ways to determine a user’s auth state:
1. Directly grab the User
As a convenience, you can grab the user object directly from the Privy instance. If the user is not null, there is an authenticated user.
2. Grab the user’s current auth state
3. Subscribe to auth state updates
A Privy user’s authentication state is defined by the AuthState
enum below.
You can retrieve the user’s AuthState
at any time via:
You can also subscribe to AuthState
updates via:
Once your user has successfully authenticated, you can get a PrivyUser
object containing their account data via:
A user’s authentication state is described by the AuthState sealed class.
The current auth state and an auth state stream are accessible directly on the Privy object.
Accessing authentication state
There are various ways to determine user’s auth state, outlined below. Mix and match to fit the needs of your application.
1. Directly retrieve the user
As a convenience, you can grab the user object directly from the Privy instance. If the user is not null, there is an authenticated user.