Plugins
Email OTP Plugin
Implement email-based one-time password authentication for secure user verification and password reset functionality.
Available Methods
Send Verification OTP
Sends a one-time password to the user's email address for verification.
final response = await client.emailOtp.sendVerificationOTP(
email: 'user@example.com',
type: 'sign-in', // Can be 'sign-in', 'email-verification', or 'forget-password'
);
Verify Email
Verifies the email address using the OTP sent to the user's email.
final response = await client.emailOtp.verifyEmail(
email: 'user@example.com',
otp: '123456',
);
Password Reset
Forget Password
Initiates the password reset process by sending an OTP to the user's email.
final response = await client.emailOtp.forgetPassword(
email: 'user@example.com',
);
Reset Password
Resets the user's password using the OTP sent to their email.
final response = await client.emailOtp.resetPassword(
email: 'user@example.com',
otp: '123456',
password: 'new-password',
);
Error Handling
All methods in the Email OTP plugin throw exceptions when operations fail. The error messages are automatically extracted from the server response and thrown as exceptions. You should wrap all email OTP plugin calls in try-catch blocks:
try {
final response = await client.emailOtp.sendVerificationOTP(
email: 'user@example.com',
type: 'sign-in',
);
// Handle success
} catch (e) {
// Handle error
print('Error: $e');
}