import { sendEmailOTP, verifyOTP, type OTPVerification} from '@dynamic-labs-sdk/client';// With the user's email, call sendEmailOTP to get the otpVerification// Then, once the user inputs the OTP code, call verifyOTP to verify it and complete the authenticationlet otpVerification: OTPVerification | null = null;const signInWithEmail = async () => { // Replace 'test@test.com' with the user's email address otpVerification = await sendEmailOTP({ email: 'test@test.com' }); // Store the otpVerification for later use with the verifyOTP function};const handleVerifyOTP = async () => { // Use the same otpVerification object that you got from the sendEmailOTP function // Replace '123456' with the OTP code entered by the user await verifyOTP({ otpVerification, verificationToken: '123456' });};
useSendEmailOTP returns the otpVerification object as its data; pass it to useVerifyOTP to complete the flow.
If a user is already signed in, verifyOTP links the email to that user instead of signing in. If the project requires step-up authentication to link an email, verification fails with HTTP 403 and “Elevated access token required”. If you intend to sign a user in, call logout() before sendEmailOTP (or useLogout in React).