sendOtp method
Send OTP manually — also updates lastTrigger for verify/resend
Implementation
Future<CkAuthResult<void>> sendOtp({
required CkOtpTrigger trigger,
required String recipient,
}) {
return loadingController.wrap(CkAuthLoadingType.sendOtp, () async {
if (config.mockAuth) {
otpManager.lastTrigger = trigger;
otpManager.lastRecipient = recipient;
await otpManager.storeVerificationToken(trigger, 'mock_otp_token');
otpManager.startResendTimer();
if (config.handlers?.showOtpVerification != null) {
config.handlers!.showOtpVerification!();
}
return CkAuthResult<void>(
isSuccess: true,
requiresOtp: true,
otpTrigger: trigger,
statusCode: 200,
rawResponse: const {'message': 'Mock OTP send successful'},
);
}
final result = await otpManager.sendOtp(
trigger: trigger,
recipient: recipient,
);
if (result.isSuccess) {
if (config.handlers?.showOtpVerification != null) {
config.handlers!.showOtpVerification!();
}
return CkAuthResult<void>(
isSuccess: true,
requiresOtp: true,
otpTrigger: trigger,
statusCode: result.statusCode,
rawResponse: result.rawResponse,
);
}
return result;
});
}