@getpara/react-sdk@alpha. This approach provides simplified state management and is recommended for most React applications.
For maximum control over authentication flow and custom React Query implementations, see the Para Client Approach.
Prerequisites
You must have a Para account set up with authentication methods enabled in your Developer Portal. Install the React SDK:Authentication States
There are three stages for an authenticating user and three correspondingAuthState types that are returned from various authentication methods:
| Stage | Meaning | Applicable Methods |
|---|---|---|
'verify' | The user is using basic authentication and must authenticate via the returned loginUrl. Or the user is using a legacy auth method, has entered their email or phone number and been sent a confirmation code via email or SMS. Alternatively, they have logged in via an external wallet and need to sign a message to verify their ownership of the wallet. | signUpOrLogIn, loginExternalWallet |
'signup' | The user has verified their email, phone number, external wallet, or completed a third-party authentication and may now create a WebAuth passkey or password to secure their account. | verifyNewAccount, verifyExternalWallet, verifyOAuth, verifyTelegram, verifyFarcaster |
'login' | The user has previously signed up and can now log in using their WebAuth passkey or password. | signUpOrLogIn , loginExternalWallet , verifyOAuth , verifyTelegram, verifyFarcaster |
'done' | The user is using basic authentication and has completed the process. | verifyOAuth, verifyTelegram, verifyFarcaster |
AuthState Type Definitions
Authentication State Management
You will most likely want to track theAuthState within your app and update it with each method resolution. For example, you may want to store it in a dedicated context:
Authentication Hooks
Phone or Email Authentication
Sign up or log in
To authenticate a user via email or phone number, use theuseSignUpOrLogIn hook. This mutation will either fetch the user with the provided authentication method and, for basic auth users, return an AuthStateVerify object or, for passkey, password and PIN users, return an AuthStateLogin object, or create a new user and return an AuthStateVerify object.
- If the user already exists they can be in one of two states:
- Basic auth users: An
AuthStateVerifystate is returned with anextStagevalue ofloginand aloginUrlthat should be opened for the user to authenticate in the Para Portal. - Passkey, password, PIN users: An
AuthStateLoginstate is returned with a combination ofpasskeyUrl,passwordUrlorpinUrlthat should be opened in a new window or tab.
- Once one of these URLs are opened, invoke the
useWaitForLoginmutation. This hook will wait until the user has completed the login process in the new window and then perform any needed setup.
- Basic auth users: An
- If the user is new, an
AuthStateVerifystate is returned with anextStagevalue ofsignupand the user can be handled one of two ways:- Basic auth users: A
loginUrlis returned on theAuthStateVerifyobject that should be opened for the user to complete sign up in the Para Portal. Once this url is opened, invoke theuseWaitForWalletCreationoruseWaitForSignupmutation. This hook will wait until the user has completed the signup process in the new window and then perform any needed setup. - Passkey, password, PIN users: No
loginUrlis returned, and the user should be prompted to enter the one-time code they received via email or SMS and that code should be verified using theuseVerifyNewAccounthook.
- Basic auth users: A
Verify new account
Not applicable to basic auth users
verify stage for passkey, password or PIN users, you will need to display an input for a six-digit code and a callback that invokes the useVerifyNewAccount hook. This will validate the one-time code and, if successful, will return an AuthStateSignup object. (The email or phone number previously entered is now stored, and will not need to be resupplied.)
Resend verification code
Not applicable to basic auth users
Sign up a new user
Basic auth users After the signUpOrLogIn process is complete, you will receive anAuthStateVerify object with a nextStage value of signup and a loginUrl. For compatibility and security, you will most likely want to open this URL in a new popup window, and then immediately invoke the useWaitForWalletCreation hook. This will wait for the user to complete signup and then create a new wallet for each wallet type you have configured in the Para Developer Portal. If you would like more control over the signup process, you can also call the useWaitForSignup hook, which will resolve after signup but bypass automatic wallet provisioning. To cancel the process in response to UI events, you can pass the isCanceled callback.
Passkey, password, PIN users
After verifyNewAccount process is complete, you will receive an AuthStateSignup object. Depending on your configuration, the AuthStateSignup will contain a Para URL for creating a WebAuth biometric passkey, a Para URL for creating a new password, or both. For compatibility and security, you will most likely want to open these URLs in a new popup window, and then immediately invoke the useWaitForWalletCreation hook. This will wait for the user to complete signup and then create a new wallet for each wallet type you have configured in the Para Developer Portal. If you would like more control over the signup process, you can also call the useWaitForSignup hook, which will resolve after signup but bypass automatic wallet provisioning. To cancel the process in response to UI events, you can pass the isCanceled callback.
Log in an existing user
Basic auth users After the signUpOrLogIn process is complete, you will receive anAuthStateVerify object with a nextStage value of login and a loginUrl. For compatibility and security, you will most likely want to open this URL in a new popup window, and then immediately invoke the useWaitForLogin hook. This will wait for the user to complete the login process and resolve when it is finished. To cancel the process in response to UI events, you can pass the isCanceled callback.
Passkey, password, PIN users
After the signUpOrLogIn process is complete, you will receive an AuthStateLogin object. Depending on the users configuration, the AuthStateLogin will contain a Para URL for creating a WebAuth biometric passkey, a Para URL for creating a new password, or both. For compatibility and security, you will most likely want to open these URLs in a new popup window, and then immediately invoke the useWaitForLogin hook. This will wait for the user to complete the login process and resolve when it is finished. To cancel the process in response to UI events, you can pass the isCanceled callback.
Third-Party Authentication Hooks
OAuth
Para supports OAuth 2.0 sign-ins via Google, Apple, Facebook, Discord, and X, provided the linked account has an email address set. Once a valid email account is fetched, the process is identical to that for email authentication, simply bypassing the one-time code verification step. To implement OAuth flow, use theuseVerifyOAuth hook.
Telegram
To implement your own Telegram authentication flow, please refer to the official documentation. Para uses the following bots to handle authentication requests:| Environment | Username | Bot ID |
|---|---|---|
BETA | @para_oauth_beta_bot | 7788006052 |
PROD | @para_oauth_bot | 7643995807 |
useVerifyTelegram hook to sign up or log in a user associated with the returned Telegram user ID. Users created via Telegram will not have an associated email address or phone number.
Farcaster
Refer to the official documentation for information on Farcaster’s SIWF (Sign In with Farcaster) feature. To use this authentication method, use theuseVerifyFarcaster hook. The hook will supply a Farcaster Connect URI, which should be displayed to your users as a QR code. Like with Telegram, users created via Farcaster will not have an associated email address or phone number.
Two-Factor Authentication Hooks
Para supports two-factor authentication via one-time codes in Google Authenticator or similar apps. To check a user’s current 2FA status, use theuseSetup2fa hook:
- If the user has already set up two-factor authentication, the
setup2famutation will return{ isSetup: true }. - If not, the mutation will return
{ isSetup: false, uri: string }, whereuriis a URI that can be scanned as a QR code by Authenticator or a similar app. - When the user has entered the code from their authenticator app, you can use the
useEnable2fahook to activate 2FA for their account. - Subsequently, you can use the
useVerify2fahook to verify the user’s account by their one-time code.
Logout
To sign out the current user, use theuseLogout hook. By default, signing out will preserve any pregenerated wallets (including guest login wallets) present in the device storage, some of which may not belong to the signed-in user. To clear all wallets, set the clearPregenWallets parameter to true.