fix login and add notifications
This commit is contained in:
@@ -65,14 +65,21 @@ final routerProvider = Provider<GoRouter>((ref) {
|
||||
redirect: (context, state) {
|
||||
final isLoading = authState.isLoading;
|
||||
final isLoggedIn = authState.value != null;
|
||||
final isOnSplashPage = state.matchedLocation == RouteNames.splash;
|
||||
final isOnLoginPage = state.matchedLocation == RouteNames.login;
|
||||
final isOnForgotPasswordPage =
|
||||
state.matchedLocation == RouteNames.forgotPassword;
|
||||
final isOnRegisterPage = state.matchedLocation == RouteNames.register;
|
||||
final isOnBusinessUnitPage =
|
||||
state.matchedLocation == RouteNames.businessUnitSelection;
|
||||
final isOnOtpPage = state.matchedLocation == RouteNames.otpVerification;
|
||||
final currentPath = state.matchedLocation;
|
||||
final targetPath = state.uri.toString();
|
||||
|
||||
// Log redirect attempts for debugging
|
||||
print('🔄 Router redirect check:');
|
||||
print(' Current: $currentPath');
|
||||
print(' Target: $targetPath');
|
||||
print(' isLoading: $isLoading, isLoggedIn: $isLoggedIn');
|
||||
|
||||
final isOnSplashPage = currentPath == RouteNames.splash;
|
||||
final isOnLoginPage = currentPath == RouteNames.login;
|
||||
final isOnForgotPasswordPage = currentPath == RouteNames.forgotPassword;
|
||||
final isOnRegisterPage = currentPath == RouteNames.register;
|
||||
final isOnBusinessUnitPage = currentPath == RouteNames.businessUnitSelection;
|
||||
final isOnOtpPage = currentPath == RouteNames.otpVerification;
|
||||
final isOnAuthPage =
|
||||
isOnLoginPage ||
|
||||
isOnForgotPasswordPage ||
|
||||
@@ -82,25 +89,35 @@ final routerProvider = Provider<GoRouter>((ref) {
|
||||
|
||||
// While loading auth state, show splash screen
|
||||
if (isLoading) {
|
||||
return RouteNames.splash;
|
||||
if (!isOnSplashPage) {
|
||||
print(' ➡️ Redirecting to splash (loading)');
|
||||
return RouteNames.splash;
|
||||
}
|
||||
print(' ✓ Already on splash (loading)');
|
||||
return null;
|
||||
}
|
||||
|
||||
// After loading, redirect from splash to appropriate page
|
||||
if (isOnSplashPage && !isLoading) {
|
||||
return isLoggedIn ? RouteNames.home : RouteNames.login;
|
||||
if (isOnSplashPage) {
|
||||
final destination = isLoggedIn ? RouteNames.home : RouteNames.login;
|
||||
print(' ➡️ Redirecting from splash to $destination');
|
||||
return destination;
|
||||
}
|
||||
|
||||
// If not logged in and not on auth/splash pages, redirect to login
|
||||
if (!isLoggedIn && !isOnAuthPage && !isOnSplashPage) {
|
||||
if (!isLoggedIn && !isOnAuthPage) {
|
||||
print(' ➡️ Redirecting to login (not authenticated)');
|
||||
return RouteNames.login;
|
||||
}
|
||||
|
||||
// If logged in and on login page, redirect to home
|
||||
if (isLoggedIn && isOnLoginPage) {
|
||||
print(' ➡️ Redirecting to home (already logged in)');
|
||||
return RouteNames.home;
|
||||
}
|
||||
|
||||
// No redirect needed
|
||||
print(' ✓ No redirect needed');
|
||||
return null;
|
||||
},
|
||||
|
||||
@@ -549,7 +566,7 @@ final routerProvider = Provider<GoRouter>((ref) {
|
||||
),
|
||||
|
||||
// Debug logging (disable in production)
|
||||
debugLogDiagnostics: true,
|
||||
debugLogDiagnostics: false, // Using custom logs instead
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user