changePassword method

Future<bool> changePassword({
  1. required PasswordChangeRequest request,
})

Change customer password

Implementation

Future<bool> changePassword({required PasswordChangeRequest request}) async {
  try {
    final response = await _client.authenticatedRequest(
      '/rest/V1/customers/me/password',
      data: request.toJson(),
    );

    return response.statusCode == 200;
  } on DioException catch (e) {
    if (e.response?.statusCode == 401) {
      throw Exception('User not authenticated');
    }
    if (e.response?.statusCode == 400) {
      final errorData = e.response?.data;
      if (errorData is Map<String, dynamic>) {
        final message = errorData['message'] ?? 'Password change failed';
        throw Exception(message);
      }
    }
    throw Exception('Password change failed: ${e.message}');
  } catch (e) {
    throw Exception('Password change failed: $e');
  }
}