Build custom authentication UI using Para’s React hooks for simplified state management
@getpara/react-sdk@alpha
. This approach provides simplified state management and is recommended for most React applications.
AuthState
types that are returned from various authentication methods:
Stage | Meaning | Applicable Methods |
---|---|---|
'verify' | The user has entered their email or phone number and been sent a confimation 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 |
AuthState
within your app and update it with each method resolution. For example, you may want to store it in a dedicated context:
useSignUpOrLogIn
hook. This mutation will either fetch the user with the provided authentication method and return an AuthStateLogin
object, or create a new user and return an AuthStateVerify
object.
passkeyUrl
or passwordUrl
in a new window or tab, then invoke the useWaitForLogin
mutation. This hook will wait until the user has completed the login process in the new window and then perform any needed setup.useVerifyNewAccount
mutation.verify
stage, 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 AuthStateLogin
object. (The email or phone number previously entered is now stored, and will not need to be resupplied.)
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.
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.
useVerifyOAuth
hook.
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.
useVerifyFarcaster
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.
useSetup2fa
hook:
setup2fa
mutation will return { isSetup: true }
.{ isSetup: false, uri: string }
, where uri
is a URI that can be scanned as a QR code by Authenticator or a similar app.useEnable2fa
hook to activate 2FA for their account.useVerify2fa
hook to verify the user’s account by their one-time code.useLogout
hook. By default, signing out will preserve any pre-generated 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
.