From 26611274d5a32324b9f5e73ae55f74032de4755e Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Tue, 31 Mar 2026 22:45:16 +0530 Subject: [PATCH] feat: pass role, agent type, and auth mode to social login providers and repository --- lib/features/auth/data/auth_repository.dart | 6 ++++ .../presentation/providers/auth_provider.dart | 28 +++++++++++++++-- .../presentation/screens/login_screen.dart | 4 +-- .../presentation/screens/signup_screen.dart | 8 +++-- .../widgets/social_login_buttons.dart | 30 ++++++++++++++++--- 5 files changed, 65 insertions(+), 11 deletions(-) diff --git a/lib/features/auth/data/auth_repository.dart b/lib/features/auth/data/auth_repository.dart index fa80474..0080e1b 100644 --- a/lib/features/auth/data/auth_repository.dart +++ b/lib/features/auth/data/auth_repository.dart @@ -137,6 +137,9 @@ class AuthRepository { required String email, String? name, String? avatar, + String? role, + String? agentTypeId, + String mode = 'signup', }) async { try { final response = await _dio.post( @@ -145,8 +148,11 @@ class AuthRepository { 'provider': provider, 'providerId': providerId, 'email': email, + 'mode': mode, if (name != null) 'name': name, if (avatar != null) 'avatar': avatar, + if (role != null) 'role': role, + if (agentTypeId != null) 'agentTypeId': agentTypeId, }, ); diff --git a/lib/features/auth/presentation/providers/auth_provider.dart b/lib/features/auth/presentation/providers/auth_provider.dart index 59acd32..3fc5973 100644 --- a/lib/features/auth/presentation/providers/auth_provider.dart +++ b/lib/features/auth/presentation/providers/auth_provider.dart @@ -178,7 +178,11 @@ class AuthNotifier extends StateNotifier { } } - Future signInWithGoogle() async { + Future signInWithGoogle({ + String? role, + String? agentTypeId, + String mode = 'signup', + }) async { state = state.copyWith( status: AuthStatus.loading, errorMessage: null, @@ -204,6 +208,9 @@ class AuthNotifier extends StateNotifier { email: account.email, name: account.displayName, avatar: account.photoUrl, + role: role, + agentTypeId: agentTypeId, + mode: mode, ); state = state.copyWith( @@ -226,7 +233,11 @@ class AuthNotifier extends StateNotifier { } } - Future signInWithFacebook() async { + Future signInWithFacebook({ + String? role, + String? agentTypeId, + String mode = 'signup', + }) async { state = state.copyWith( status: AuthStatus.loading, errorMessage: null, @@ -273,6 +284,9 @@ class AuthNotifier extends StateNotifier { email: email, name: userData['name'] as String?, avatar: avatarUrl, + role: role, + agentTypeId: agentTypeId, + mode: mode, ); state = state.copyWith( @@ -296,7 +310,12 @@ class AuthNotifier extends StateNotifier { } /// Complete Twitter/X login after webview returns user data. - Future completeTwitterLogin(Map twitterUser) async { + Future completeTwitterLogin( + Map twitterUser, { + String? role, + String? agentTypeId, + String mode = 'signup', + }) async { state = state.copyWith( status: AuthStatus.loading, errorMessage: null, @@ -310,6 +329,9 @@ class AuthNotifier extends StateNotifier { email: '${twitterUser['username']}@x.com', name: twitterUser['name'] as String?, avatar: twitterUser['avatar'] as String?, + role: role, + agentTypeId: agentTypeId, + mode: mode, ); state = state.copyWith( diff --git a/lib/features/auth/presentation/screens/login_screen.dart b/lib/features/auth/presentation/screens/login_screen.dart index b5efeaf..4506e4f 100644 --- a/lib/features/auth/presentation/screens/login_screen.dart +++ b/lib/features/auth/presentation/screens/login_screen.dart @@ -240,8 +240,8 @@ class _LoginScreenState extends ConsumerState { const OrDivider(), const SizedBox(height: 24), - // Social login buttons - const SocialLoginButtons(), + // Social login buttons (login mode — reject if user doesn't exist) + const SocialLoginButtons(mode: 'login'), const SizedBox(height: 40), ], ), diff --git a/lib/features/auth/presentation/screens/signup_screen.dart b/lib/features/auth/presentation/screens/signup_screen.dart index 7005c57..bc909d0 100644 --- a/lib/features/auth/presentation/screens/signup_screen.dart +++ b/lib/features/auth/presentation/screens/signup_screen.dart @@ -443,8 +443,12 @@ class _SignupScreenState extends ConsumerState { const OrDivider(), const SizedBox(height: 24), - // Social login buttons - const SocialLoginButtons(), + // Social login buttons (signup mode with role and agent type) + SocialLoginButtons( + mode: 'signup', + role: _selectedRole, + agentTypeId: _selectedAgentTypeId, + ), const SizedBox(height: 40), ], ); diff --git a/lib/features/auth/presentation/widgets/social_login_buttons.dart b/lib/features/auth/presentation/widgets/social_login_buttons.dart index ab814f5..2487d1c 100644 --- a/lib/features/auth/presentation/widgets/social_login_buttons.dart +++ b/lib/features/auth/presentation/widgets/social_login_buttons.dart @@ -6,7 +6,16 @@ import 'package:real_estate_mobile/features/auth/presentation/providers/auth_pro import 'package:real_estate_mobile/features/auth/presentation/screens/twitter_login_screen.dart'; class SocialLoginButtons extends ConsumerWidget { - const SocialLoginButtons({super.key}); + final String? role; + final String? agentTypeId; + final String mode; + + const SocialLoginButtons({ + super.key, + this.role, + this.agentTypeId, + this.mode = 'signup', + }); void _showComingSoon(BuildContext context) { ScaffoldMessenger.of(context).showSnackBar( @@ -24,7 +33,12 @@ class SocialLoginButtons extends ConsumerWidget { MaterialPageRoute(builder: (_) => const TwitterLoginScreen()), ); if (result != null) { - ref.read(authProvider.notifier).completeTwitterLogin(result); + ref.read(authProvider.notifier).completeTwitterLogin( + result, + role: role, + agentTypeId: agentTypeId, + mode: mode, + ); } } @@ -50,7 +64,11 @@ class SocialLoginButtons extends ConsumerWidget { _SocialButton( onTap: isLoading ? null - : () => ref.read(authProvider.notifier).signInWithGoogle(), + : () => ref.read(authProvider.notifier).signInWithGoogle( + role: role, + agentTypeId: agentTypeId, + mode: mode, + ), child: SvgPicture.asset( 'assets/icons/google.svg', width: 24, @@ -74,7 +92,11 @@ class SocialLoginButtons extends ConsumerWidget { _SocialButton( onTap: isLoading ? null - : () => ref.read(authProvider.notifier).signInWithFacebook(), + : () => ref.read(authProvider.notifier).signInWithFacebook( + role: role, + agentTypeId: agentTypeId, + mode: mode, + ), child: SvgPicture.asset( 'assets/icons/facebook.svg', width: 24,