fix login and add notifications

This commit is contained in:
Phuoc Nguyen
2025-11-26 17:46:09 +07:00
parent 88ac2f2f07
commit dc8e60f589
14 changed files with 517 additions and 33 deletions

View File

@@ -569,7 +569,7 @@ Future<AuthInterceptor> authInterceptor(Ref ref, Dio dio) async {
@riverpod
LoggingInterceptor loggingInterceptor(Ref ref) {
// Only enable logging in debug mode
const bool isDebug = true; // TODO: Replace with kDebugMode from Flutter
const bool isDebug = false; // TODO: Replace with kDebugMode from Flutter
return LoggingInterceptor(
enableRequestLogging: false,

View File

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