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,
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,
},
);

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(
status: AuthStatus.loading,
errorMessage: null,
@@ -204,6 +208,9 @@ class AuthNotifier extends StateNotifier<AuthState> {
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<AuthState> {
}
}
Future<void> signInWithFacebook() async {
Future<void> 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<AuthState> {
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<AuthState> {
}
/// 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(
status: AuthStatus.loading,
errorMessage: null,
@@ -310,6 +329,9 @@ class AuthNotifier extends StateNotifier<AuthState> {
email: '${twitterUser['username']}@x.com',
name: twitterUser['name'] as String?,
avatar: twitterUser['avatar'] as String?,
role: role,
agentTypeId: agentTypeId,
mode: mode,
);
state = state.copyWith(

View File

@@ -240,8 +240,8 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
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),
],
),

View File

@@ -443,8 +443,12 @@ class _SignupScreenState extends ConsumerState<SignupScreen> {
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),
],
);

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';
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,