Google OAuth login may not work in in-app browsers (IABs), such as those embedded in social apps,
due to Google’s restrictions in these environments. Other OAuth providers are generally
unaffected.
Enable your desired OAuth login method in the Privy
Dashboard before implementing
this feature.
The SDK supports OAuth login with . For all other OAuth providers, you can
use JWT-based authentication.
To authenticate your users with Privy’s out of the box UIs, check out UI components here.
initOAuth
from the useLoginWithOAuth
hook to trigger the OAuth login flow.The OAuth provider to use for authentication. Valid values are:
'google'
, 'apple'
, 'twitter'
,
'github'
, 'discord'
, 'linkedin'
, 'spotify'
, 'tiktok'
, 'instagram'
, 'line'
.If set to true, the OAuth flow will only allow users to log in with existing accounts and prevent new account creation.
Usage
Tracking Flow State
Track the state of the OAuth flow via thestate
variable returned by the useLoginWithOAuth
hook.The current state of the OAuth flow.
The error that occurred during the OAuth flow (only present when status is ‘error’).
Callbacks
You can optionally pass callbacks to theuseLoginWithOAuth
hook to run custom logic after a successful login or to handle errors.onSuccess
Parameters
The user object returned after successful login.
Whether the user is a new user or an existing user.
Whether the user was already authenticated before the OAuth flow.
The login method used (‘google’, ‘apple’, etc.).
The linked account if the user was already authenticated.
onError
Parameters
The error that occurred during the OAuth flow.