useConnectWithOtp
Allow for headless email or sms OTP authentication
Summary
This hook allows for authenticating a user using email or sms OTP without the standard Dynamic SDK.
How it works
The useConnectWithOtp
hook exposes the connectWithEmail
, connectWithSms
and verifyOneTimePassword
functions, with these functions you can send an OTP to a user and then verify the OTP code the user received.
The hook works with Dynamic User Verification provider.
Method | Type | Description |
---|---|---|
connectWithEmail | (email: string) => Promise | Sends the OTP to the provided email |
connectWithSms | (phone: PhoneData) => Promise | Sends the OTP to the provided phone |
verifyOneTimePassword | (oneTimePassword: string) => Promise | Verify the provided OTP. The returned promise will be resolved if the OTP is valid or it will be rejected if the OTP is invalid |
Examples
Verify user with email OTP headless
This will display a field to input the email when the user is not authenticated or a field to verify the OTP code if the user is already authenticated. Once the OTP is verified, the Dynamic SDK will be authenticated and you can find the user object using the useDynamicContext hook.
Verify user with sms OTP headless
This will display three fields to input the phone data when the user is not authenticated: country iso code (e.g: ‘US’), country dial code (e.g. ‘1’) and phone number (e.g. ‘5555555555’) If user is already authenticated, it will display a field to verify the OTP code. Once the OTP is verified, the Dynamic SDK will be authenticated and you can find the user object using the useDynamicContext hook.
Was this page helpful?