validateOtp method

Future<BagelUser?> validateOtp(
  1. String otp, {
  2. String nonce = '',
})

Validate the user's received One Time Password

Implementation

Future<BagelUser?> validateOtp(String otp, {String nonce = ''}) async {
  String? _nonce = _getOtpRequestNonce() ?? nonce;
  if (_nonce.isEmpty)
    throw ("Couldn't find OTP nonce, please run requestOTP first");
  String url = '$authEndpoint/user/otp/verify/$_nonce?t=${DateTime.now()}';
  Map body = {"otp": otp};
  try {
    Response res = await dio.post(url, data: body);
    _storeTokens(res.data);
    return _getUser();
  } catch (e) {
    if (e is DioException) throw (e.response.toString());
  }
  return null;
}