confirmOtp method
Confirm the OTP challenge with code. Returns true if the
verification succeeded, false if the code was rejected, and rethrows
on a non-validation error (after storing the error on error and
notifying listeners).
A blank code is treated as a no-op (returns false without hitting
the network). Calling this in a state other than
CrossmintEmailSignInStep.otpInput also returns false without
touching the network.
Implementation
Future<bool> confirmOtp(String code) async {
final String trimmed = code.trim();
if (trimmed.isEmpty ||
_emailId == null ||
_step != CrossmintEmailSignInStep.otpInput) {
return false;
}
_isLoading = true;
_error = null;
_safeNotify();
try {
final bool success = await _auth.confirmEmailOtp(
email: _submittedEmail,
emailId: _emailId!,
token: trimmed,
);
if (_disposed) {
return success;
}
if (!success) {
_error = 'Invalid code. Please try again.';
}
return success;
} on Exception catch (_) {
if (!_disposed) {
_error = "Couldn't verify code. Please try again.";
}
rethrow;
} finally {
if (!_disposed) {
_isLoading = false;
_safeNotify();
}
}
}