feat: implement social login functionality with Google, Facebook, and Twitter, including API integration and platform-specific configurations.
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user