df
This commit is contained in:
@@ -51,24 +51,36 @@ class AppRouter {
|
||||
final isGoingToLogin = state.matchedLocation == '/login';
|
||||
final isGoingToOnboarding = state.matchedLocation == '/onboarding';
|
||||
final isGoingToSetPassword = state.matchedLocation == '/set-password';
|
||||
|
||||
// 1. LA PASSATOIA VIP (DEVE ESSERE IN CIMA)
|
||||
// Usiamo state.uri.path perché state.matchedLocation a volte fa i capricci coi deep link iniziali
|
||||
final isPublicRoute = state.uri.path.startsWith('/upload');
|
||||
|
||||
if (isPublicRoute) {
|
||||
return null; // Null significa "Non reindirizzare, lascialo passare"
|
||||
// Ritorna null esplicitamente per dire al router "Rimani qui e non fare altri controlli"
|
||||
return null;
|
||||
}
|
||||
|
||||
// 2. CONTROLLO INIZIALE
|
||||
// Se la sessione sta ancora caricando la primissima volta (es. splash screen logico)
|
||||
if (sessionState.status == SessionStatus.initial) return null;
|
||||
|
||||
// 3. UTENTE NON LOGGATO (Ma ci arriva solo se non è su /upload)
|
||||
if (sessionState.status == SessionStatus.unauthenticated) {
|
||||
// Se sta già andando alle uniche altre pagine pubbliche, lascialo andare
|
||||
if (isGoingToLogin || isGoingToSetPassword) return null;
|
||||
// Altrimenti bloccalo e mandalo al login
|
||||
return '/login';
|
||||
}
|
||||
|
||||
// 4. UTENTE LOGGATO MA DEVE COMPLETARE L'ONBOARDING
|
||||
if (sessionState.status == SessionStatus.onboardingRequired) {
|
||||
return isGoingToOnboarding ? null : '/onboarding';
|
||||
}
|
||||
|
||||
// 5. UTENTE PERFETTAMENTE LOGGATO E OPERATIVO
|
||||
if (sessionState.status == SessionStatus.authenticated) {
|
||||
// Se per sbaglio cerca di tornare al login o all'onboarding, ributtalo in dashboard
|
||||
if (isGoingToLogin || isGoingToOnboarding) return '/';
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import 'package:flux/features/master_data/store/bloc/store_cubit.dart';
|
||||
import 'package:flux/features/master_data/store/data/store_repository.dart';
|
||||
import 'package:flux/features/operations/blocs/operations_cubit.dart';
|
||||
import 'package:flux/features/settings/settings.dart';
|
||||
import 'package:flutter_web_plugins/url_strategy.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
@@ -37,7 +38,8 @@ void main() async {
|
||||
|
||||
// Inizializza le dipendenze PRIMA di lanciare l'app
|
||||
await setupLocator();
|
||||
|
||||
// RIMUOVE IL CARATTERE # DAGLI URL WEB!
|
||||
usePathUrlStrategy();
|
||||
runApp(
|
||||
MultiBlocProvider(
|
||||
providers: [
|
||||
|
||||
Reference in New Issue
Block a user