socialLogin method

Future<AuthResponse> socialLogin({
  1. required String provider,
  2. required String token,
  3. String? email,
  4. String? firstname,
  5. String? lastname,
})

Social login

Implementation

Future<AuthResponse> socialLogin({
  required String provider,
  required String token,
  String? email,
  String? firstname,
  String? lastname,
}) async {
  try {
    // This endpoint might need to be customized based on Magento setup
    final response = await _client.guestRequest<Map<String, dynamic>>(
      '/rest/V1/integration/social/login',
      data: {
        'provider': provider,
        'token': token,
        'email': email,
        'firstname': firstname,
        'lastname': lastname,
      },
    );

    if (response.statusCode == 200) {
      final authResponse = AuthResponse.fromJson(response.data!);

      // Store tokens
      await _client.storeTokens(
        accessToken: authResponse.accessToken,
        refreshToken: authResponse.refreshToken,
        customerId: authResponse.customer.id,
      );

      return authResponse;
    } else {
      throw Exception('Social login failed: ${response.statusMessage}');
    }
  } on DioException catch (e) {
    throw Exception('Social login failed: ${e.message}');
  } catch (e) {
    throw Exception('Social login failed: $e');
  }
}