Authenticating Users via OTP
This guide assumes you have already followed the Setup Guide and have set up the Alchemy Account Provider using this guide. Please refer to the guides above for more information on how to properly setup your project.
For a complete example of how we can setup a project and use the various available authentication methods, please refer to our quickstart example.
Authenticating a user is easy using the useAuthenticate()
hook from the @account-kit/react-native
package.
Set the Email Mode to One Time Password (OTP)
in your Account Kit Dashboard
This is the default mode for email authentication. Only follow these steps if
you had previously set the email mode to Magic Link
.
In your Alchemy Accounts Dashboard:
-
Navigate to the Smart Wallets tab
-
Select the config you would be using for your project and click the Edit button
-
Scroll down to the Email Mode options in the Email section and select One Time Password (OTP)
-
Click the Save Changes button
Send a One-Time Password (OTP) to a User
To send an OTP to a user’s email, use the authenticate()
function from the useAuthenticate()
hook with the type
set to email
and the emailMode
set to otp
.
Prompt the User to enter the One-Time Password to complete authentication
The user will receive an email with a one-time password (OTP) to enter into your app.
Provide a means for the user to enter the OTP into your app and then call the authenticate()
function from the useAuthenticate()
hook passing the OTP code to the otpCode
parameter, and the type
set to otp
.
Here’s an example of a Sign In component using OTP. Feel free to embed this into your application to give it a try!