diff --git a/app/src/main/java/app/closer/core/navigation/AppNavigation.kt b/app/src/main/java/app/closer/core/navigation/AppNavigation.kt index fd8d1f7f..0a86fed2 100644 --- a/app/src/main/java/app/closer/core/navigation/AppNavigation.kt +++ b/app/src/main/java/app/closer/core/navigation/AppNavigation.kt @@ -124,9 +124,29 @@ fun AppNavigation( selectTab(AppRoute.HOME) } } + // The pre-app entry flow (onboarding + profile/pairing setup + auth). Leaving any of + // these for Home must CLEAR them from the back stack — otherwise the graph start + // (ONBOARDING) lingers as the root under Home and a system Back from Home walks + // backward into the onboarding carousel / login screen, making a signed-in user look + // logged out (C-NAV-001). + val entryRoutes = setOf( + AppRoute.ONBOARDING, + AppRoute.CREATE_PROFILE, + AppRoute.PAIR_PROMPT, + AppRoute.LOGIN, + AppRoute.SIGN_UP, + AppRoute.FORGOT_PASSWORD + ) val navigateRoute: (String) -> Unit = { route -> when { route == "back" -> navigateBackOrHome() + // Completing onboarding/auth: make Home the back-stack root (wipe the entire + // entry flow) so Back from Home exits the app, never resurfaces onboarding/login. + route == AppRoute.HOME && currentRoute in entryRoutes -> + navController.navigate(AppRoute.HOME) { + popUpTo(0) { inclusive = true } + launchSingleTop = true + } // Top-level tabs must use tab-switch semantics. Plain-navigating to a // tab (e.g. a "Game waiting" card → PLAY) would stack it on the current // tab; the bottom bar then saves that substack and `restoreState` later