Custom Authentication UI
Use Paraβs provided React hooks to create your own authentication UI
We strongly recommend against this approach unless you have exhausted the configuration options available and will be planning to dedicate bandwidth to maintain this flow, as it is more time-intensive to build and maintain than the Para Modal.
Development support for Custom UI is only available starting in the Scale Tier.
Authentication States
There are three stages for an authenticating user and three corresponding 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 |
Below are the type definitions for each AuthState
subtype:
You will most likely want to track the AuthState
within your app and update it with each method resolution. For example, you may want to store it in a dedicated context:
Phone or email accounts
Sign up or log in
To authenticate a user via email or phone number, use the 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.
- If the user already exists, you will need to open either the
passkeyUrl
orpasswordUrl
in a new window or tab, then invoke theuseWaitForLogin
mutation. This hook will wait until the user has completed the login process in the new window and then perform any needed setup. - If the user is new, you will then need to display a verification code input and later invoke the
useVerifyNewAccount
mutation.
Verify new account
While in the 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.)
Resend verification code
You can present a button to resend the verification code to the userβs email or phone in case they need a second one.
Sign up a new user
After verification 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
Depending on your 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
For third-party authentication, the OTP verification step is bypassed. A successful authentication will advance your application to either the login or signup stage immediately.
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 the useVerifyOAuth
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 |
Once a Telegram authentication response is received, you can invoke the 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 the 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.
Two-factor authentication
Para supports two-factor authentication via one-time codes in Google Authenticator or similar apps. To check a userβs current 2FA status, use the useSetup2fa
hook:
- If the user has already set up two-factor authentication, the
setup2fa
mutation will return{ isSetup: true }
. - If not, the mutation will return
{ isSetup: false, uri: string }
, whereuri
is 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
useEnable2fa
hook to activate 2FA for their account. - Subsequently, you can use the
useVerify2fa
hook to verify the userβs account by their one-time code.
Logout
To sign out the current user, use the 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
.