verifyOtp method

  1. @override
Future<AuthResult<bool>> verifyOtp(
  1. String contact,
  2. String otp,
  3. AuthMethod method
)
override

Implementation

@override
Future<AuthResult<bool>> verifyOtp(String contact, String otp, AuthMethod method) async {
  try {
    final response = await _client.post(
      Uri.parse('$baseUrl/auth/verify-otp'),
      headers: _headers,
      body: jsonEncode({'contact': contact, 'otp': otp, 'method': method.name}),
    );
    final result = _handleResponse<Map<String, dynamic>>(response, (json) => json);
    return result.fold(
      (data) => AuthResult.success(data['verified'] as bool? ?? false),
      (error) => AuthResult.failure(error),
    );
  } catch (e) {
    return AuthResult.failure(AuthException(e.toString(), code: 'network-error'));
  }
}