Skip to main content

Overview

This guide shows how to implement OTP authentication using turnkey_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 TurnkeyConfig is pointing at the correct authProxyConfigId (OTP settings are controlled in the dashboard).

Request an OTP (email)

Create or update your login screen to request an email OTP using initOtp. 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, pass contact 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 initOtp again with the same contact.
  • For SMS, replace OtpType.Email with OtpType.Sms and pass a phone number in contact.