feat: implement social login functionality with Google, Facebook, and Twitter, including API integration and platform-specific configurations.

This commit is contained in:
pradeepkumar
2026-03-26 00:07:31 +05:30
parent ad2d50138a
commit c5f905b4d3
14 changed files with 479 additions and 14 deletions

View File

@@ -130,6 +130,44 @@ class AuthRepository {
}
}
/// Social auth (Google, Facebook, etc.) — calls POST /auth/social
Future<UserModel> socialAuth({
required String provider,
required String providerId,
required String email,
String? name,
String? avatar,
}) async {
try {
final response = await _dio.post(
ApiConstants.authSocial,
data: {
'provider': provider,
'providerId': providerId,
'email': email,
if (name != null) 'name': name,
if (avatar != null) 'avatar': avatar,
},
);
final data = response.data['data'] as Map<String, dynamic>;
final authResponse = AuthResponse.fromJson(data);
await SecureStorage.saveTokens(
accessToken: authResponse.accessToken,
refreshToken: authResponse.refreshToken,
);
return authResponse.user;
} on DioException catch (e) {
if (e.error is ApiException) throw e.error as ApiException;
throw ApiException(
message: e.message ?? 'Social login failed',
statusCode: e.response?.statusCode,
);
}
}
/// Register returns { message, user } — no tokens.
/// The user must verify their email before logging in.
Future<Map<String, dynamic>> register(RegisterRequest request) async {