feat: pass role, agent type, and auth mode to social login providers and repository

This commit is contained in:
pradeepkumar
2026-03-31 22:45:16 +05:30
parent c2c1b51777
commit 26611274d5
5 changed files with 65 additions and 11 deletions

View File

@@ -137,6 +137,9 @@ class AuthRepository {
required String email, required String email,
String? name, String? name,
String? avatar, String? avatar,
String? role,
String? agentTypeId,
String mode = 'signup',
}) async { }) async {
try { try {
final response = await _dio.post( final response = await _dio.post(
@@ -145,8 +148,11 @@ class AuthRepository {
'provider': provider, 'provider': provider,
'providerId': providerId, 'providerId': providerId,
'email': email, 'email': email,
'mode': mode,
if (name != null) 'name': name, if (name != null) 'name': name,
if (avatar != null) 'avatar': avatar, if (avatar != null) 'avatar': avatar,
if (role != null) 'role': role,
if (agentTypeId != null) 'agentTypeId': agentTypeId,
}, },
); );

View File

@@ -178,7 +178,11 @@ class AuthNotifier extends StateNotifier<AuthState> {
} }
} }
Future<void> signInWithGoogle() async { Future<void> signInWithGoogle({
String? role,
String? agentTypeId,
String mode = 'signup',
}) async {
state = state.copyWith( state = state.copyWith(
status: AuthStatus.loading, status: AuthStatus.loading,
errorMessage: null, errorMessage: null,
@@ -204,6 +208,9 @@ class AuthNotifier extends StateNotifier<AuthState> {
email: account.email, email: account.email,
name: account.displayName, name: account.displayName,
avatar: account.photoUrl, avatar: account.photoUrl,
role: role,
agentTypeId: agentTypeId,
mode: mode,
); );
state = state.copyWith( state = state.copyWith(
@@ -226,7 +233,11 @@ class AuthNotifier extends StateNotifier<AuthState> {
} }
} }
Future<void> signInWithFacebook() async { Future<void> signInWithFacebook({
String? role,
String? agentTypeId,
String mode = 'signup',
}) async {
state = state.copyWith( state = state.copyWith(
status: AuthStatus.loading, status: AuthStatus.loading,
errorMessage: null, errorMessage: null,
@@ -273,6 +284,9 @@ class AuthNotifier extends StateNotifier<AuthState> {
email: email, email: email,
name: userData['name'] as String?, name: userData['name'] as String?,
avatar: avatarUrl, avatar: avatarUrl,
role: role,
agentTypeId: agentTypeId,
mode: mode,
); );
state = state.copyWith( state = state.copyWith(
@@ -296,7 +310,12 @@ class AuthNotifier extends StateNotifier<AuthState> {
} }
/// Complete Twitter/X login after webview returns user data. /// Complete Twitter/X login after webview returns user data.
Future<void> completeTwitterLogin(Map<String, dynamic> twitterUser) async { Future<void> completeTwitterLogin(
Map<String, dynamic> twitterUser, {
String? role,
String? agentTypeId,
String mode = 'signup',
}) async {
state = state.copyWith( state = state.copyWith(
status: AuthStatus.loading, status: AuthStatus.loading,
errorMessage: null, errorMessage: null,
@@ -310,6 +329,9 @@ class AuthNotifier extends StateNotifier<AuthState> {
email: '${twitterUser['username']}@x.com', email: '${twitterUser['username']}@x.com',
name: twitterUser['name'] as String?, name: twitterUser['name'] as String?,
avatar: twitterUser['avatar'] as String?, avatar: twitterUser['avatar'] as String?,
role: role,
agentTypeId: agentTypeId,
mode: mode,
); );
state = state.copyWith( state = state.copyWith(

View File

@@ -240,8 +240,8 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
const OrDivider(), const OrDivider(),
const SizedBox(height: 24), const SizedBox(height: 24),
// Social login buttons // Social login buttons (login mode — reject if user doesn't exist)
const SocialLoginButtons(), const SocialLoginButtons(mode: 'login'),
const SizedBox(height: 40), const SizedBox(height: 40),
], ],
), ),

View File

@@ -443,8 +443,12 @@ class _SignupScreenState extends ConsumerState<SignupScreen> {
const OrDivider(), const OrDivider(),
const SizedBox(height: 24), const SizedBox(height: 24),
// Social login buttons // Social login buttons (signup mode with role and agent type)
const SocialLoginButtons(), SocialLoginButtons(
mode: 'signup',
role: _selectedRole,
agentTypeId: _selectedAgentTypeId,
),
const SizedBox(height: 40), const SizedBox(height: 40),
], ],
); );

View File

@@ -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'; import 'package:real_estate_mobile/features/auth/presentation/screens/twitter_login_screen.dart';
class SocialLoginButtons extends ConsumerWidget { 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) { void _showComingSoon(BuildContext context) {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
@@ -24,7 +33,12 @@ class SocialLoginButtons extends ConsumerWidget {
MaterialPageRoute(builder: (_) => const TwitterLoginScreen()), MaterialPageRoute(builder: (_) => const TwitterLoginScreen()),
); );
if (result != null) { 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( _SocialButton(
onTap: isLoading onTap: isLoading
? null ? null
: () => ref.read(authProvider.notifier).signInWithGoogle(), : () => ref.read(authProvider.notifier).signInWithGoogle(
role: role,
agentTypeId: agentTypeId,
mode: mode,
),
child: SvgPicture.asset( child: SvgPicture.asset(
'assets/icons/google.svg', 'assets/icons/google.svg',
width: 24, width: 24,
@@ -74,7 +92,11 @@ class SocialLoginButtons extends ConsumerWidget {
_SocialButton( _SocialButton(
onTap: isLoading onTap: isLoading
? null ? null
: () => ref.read(authProvider.notifier).signInWithFacebook(), : () => ref.read(authProvider.notifier).signInWithFacebook(
role: role,
agentTypeId: agentTypeId,
mode: mode,
),
child: SvgPicture.asset( child: SvgPicture.asset(
'assets/icons/facebook.svg', 'assets/icons/facebook.svg',
width: 24, width: 24,