verifyOtp method

Future<CkAuthResult<void>> verifyOtp({
  1. required String otp,
})

Verify OTP — uses stored verification token automatically

Implementation

Future<CkAuthResult<void>> verifyOtp({required String otp}) {
  return loadingController.wrap(CkAuthLoadingType.verifyOtp, () async {
    if (config.mockAuth) {
      final activeTrigger = otpManager.lastTrigger;
      if (activeTrigger == CkOtpTrigger.signup) {
        _preSignupOtpVerified = true; // allow next signUp to bypass OTP
        final res = await _resolvePostSignupAuth(
          responseData: const {'message': 'Mock OTP verification successful'},
          statusCode: 200,
        );
        return CkAuthResult<void>(
          isSuccess: res.isSuccess,
          message: res.message,
          statusCode: res.statusCode,
          rawResponse: res.rawResponse,
        );
      } else if (activeTrigger == CkOtpTrigger.forgetPassword) {
        config.handlers?.showResetPassword?.call();
      }
      return const CkAuthResult<void>.success(
        statusCode: 200,
        rawResponse: {'message': 'Mock OTP verification successful'},
      );
    }
    final activeTrigger = otpManager.lastTrigger;

    final verifyResult = await otpManager.verifyOtp(otp: otp);

    if (verifyResult.isSuccess) {
      if (activeTrigger == CkOtpTrigger.signup) {
        final res = await _resolvePostSignupAuth(
          responseData: verifyResult.rawResponse,
          statusCode: verifyResult.statusCode,
          calledFromVerifyOtp: true,
        );
        return CkAuthResult<void>(
          isSuccess: res.isSuccess,
          message: res.message,
          statusCode: res.statusCode,
          rawResponse: res.rawResponse,
        );
      } else if (activeTrigger == CkOtpTrigger.forgetPassword) {
        if (config.handlers?.showResetPassword != null) {
          config.handlers!.showResetPassword!();
        }
      }
      return const CkAuthResult<void>.success();
    }

    return verifyResult;
  });
}