Overview
This guide shows how to implement OTP authentication usingturnkey_sdk_flutter. You’ll trigger an OTP to a user’s email address (or phone number), navigate to a verification screen, and verify the 6-digit code.
Before you begin:
- Complete the provider setup from Getting Started and enable Auth Proxy with Email OTP and/or SMS OTP in the Turnkey Dashboard.
- Ensure your
TurnkeyConfigis pointing at the correctauthProxyConfigId(OTP settings are controlled in the dashboard).
Request an OTP (email)
Create or update your login screen to request an email OTP usinginitOtp. The snippet below navigates to an OTP screen with the returned otpId and the email address.
lib/screens/login.dart
Verify the OTP code
On the OTP screen, passcontact and otpId via the constructor and call loginOrSignUpWithOtp with the 6-digit code.
lib/screens/otp.dart
Notes
- The default OTP length is 6; if you customized OTP settings in the dashboard, validate accordingly.
- To resend a code, call
initOtpagain with the same contact. - For SMS, replace
OtpType.EmailwithOtpType.Smsand pass a phone number incontact.