feat: route agents to the profile screen instead of home upon authentication
This commit is contained in:
@@ -65,7 +65,10 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
|
|||||||
// Navigate on auth state changes
|
// Navigate on auth state changes
|
||||||
ref.listen<AuthState>(authProvider, (previous, next) {
|
ref.listen<AuthState>(authProvider, (previous, next) {
|
||||||
if (next.status == AuthStatus.authenticated) {
|
if (next.status == AuthStatus.authenticated) {
|
||||||
context.go('/home');
|
// Agents land on /profile (defaults to "Edit Profile" tab —
|
||||||
|
// their dashboard/home view). Users land on /home.
|
||||||
|
final isAgent = next.user?.role == 'AGENT';
|
||||||
|
context.go(isAgent ? '/profile' : '/home');
|
||||||
}
|
}
|
||||||
// Navigate to 2FA verification screen
|
// Navigate to 2FA verification screen
|
||||||
if (next.requiresTwoFactor && next.tempToken != null) {
|
if (next.requiresTwoFactor && next.tempToken != null) {
|
||||||
|
|||||||
@@ -95,10 +95,12 @@ class _Verify2faScreenState extends ConsumerState<Verify2faScreen> {
|
|||||||
final authState = ref.watch(authProvider);
|
final authState = ref.watch(authProvider);
|
||||||
final isLoading = authState.status == AuthStatus.loading;
|
final isLoading = authState.status == AuthStatus.loading;
|
||||||
|
|
||||||
// Navigate to home when authentication succeeds, reset submit lock on error.
|
// Navigate when authentication succeeds, reset submit lock on error.
|
||||||
|
// Agents land on /profile (Edit Profile tab — their home/dashboard view).
|
||||||
ref.listen<AuthState>(authProvider, (previous, next) {
|
ref.listen<AuthState>(authProvider, (previous, next) {
|
||||||
if (next.status == AuthStatus.authenticated) {
|
if (next.status == AuthStatus.authenticated) {
|
||||||
context.go('/home');
|
final isAgent = next.user?.role == 'AGENT';
|
||||||
|
context.go(isAgent ? '/profile' : '/home');
|
||||||
}
|
}
|
||||||
if (next.status != AuthStatus.loading) {
|
if (next.status != AuthStatus.loading) {
|
||||||
_isSubmitting = false;
|
_isSubmitting = false;
|
||||||
|
|||||||
@@ -1,18 +1,20 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:real_estate_mobile/core/constants/app_colors.dart';
|
import 'package:real_estate_mobile/core/constants/app_colors.dart';
|
||||||
|
import 'package:real_estate_mobile/features/auth/presentation/providers/auth_provider.dart';
|
||||||
|
|
||||||
class SplashScreen extends StatefulWidget {
|
class SplashScreen extends ConsumerStatefulWidget {
|
||||||
const SplashScreen({super.key});
|
const SplashScreen({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<SplashScreen> createState() => _SplashScreenState();
|
ConsumerState<SplashScreen> createState() => _SplashScreenState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SplashScreenState extends State<SplashScreen>
|
class _SplashScreenState extends ConsumerState<SplashScreen>
|
||||||
with SingleTickerProviderStateMixin {
|
with SingleTickerProviderStateMixin {
|
||||||
late final AnimationController _controller;
|
late final AnimationController _controller;
|
||||||
late final Animation<double> _fadeAnimation;
|
late final Animation<double> _fadeAnimation;
|
||||||
@@ -43,11 +45,15 @@ class _SplashScreenState extends State<SplashScreen>
|
|||||||
final onboardingCompleted = prefs.getBool('onboarding_completed') ?? false;
|
final onboardingCompleted = prefs.getBool('onboarding_completed') ?? false;
|
||||||
|
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
if (onboardingCompleted) {
|
if (!onboardingCompleted) {
|
||||||
context.go('/home');
|
|
||||||
} else {
|
|
||||||
context.go('/onboarding');
|
context.go('/onboarding');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
// Agents land on /profile (Edit Profile tab); everyone else on /home.
|
||||||
|
final authState = ref.read(authProvider);
|
||||||
|
final isAgent = authState.status == AuthStatus.authenticated &&
|
||||||
|
authState.user?.role == 'AGENT';
|
||||||
|
context.go(isAgent ? '/profile' : '/home');
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
Reference in New Issue
Block a user