ursus
02/26/2026, 9:58 PMnav3 how do you handle "go to login screen on logout"?
Should I have some sort of on-off LogOutEvent which reset the backstack and sets login screen?
Or should it better be derived from state, ie. Flow<User?> emittnit null?
I think I like the stateful way more
@Composable
fun AppRoot() {
val user = userFlow.collectAsStateWithLifecycle().value
LaunchedEffect(key1 = user) {
if (user == null) {
backStack.clear()
backStack.add(element = LoginKey)
}
}
but on activity recreation this obviously clears the backstack again .. so no good
unless I keep a flag on each Screen type if it's "inside logged in part"
or is there a better way?
What about NavDisplay per app state? (logged in, logged out)?Pablichjenkov
02/27/2026, 3:17 AMmalik bilal
02/27/2026, 5:04 AMursus
02/27/2026, 9:21 AMmalik bilal
02/27/2026, 9:29 AMursus
02/27/2026, 9:38 AMursus
02/27/2026, 9:39 AMursus
02/27/2026, 3:58 PMPablichjenkov
02/27/2026, 4:30 PMPablichjenkov
02/27/2026, 4:31 PMPablichjenkov
02/27/2026, 4:31 PMursus
02/27/2026, 4:32 PMPablichjenkov
02/27/2026, 5:00 PMursus
02/27/2026, 5:01 PMPablichjenkov
02/27/2026, 7:59 PMursus
02/27/2026, 8:47 PMPablichjenkov
02/27/2026, 9:42 PMIan Lake
02/27/2026, 9:46 PMval backStackToPassToNavDisplay = if (user == null) {
loginBackStack
} else {
backStack
}
And then your login code is
user = newlyLoggedInUser
// Reset the login back stack to
// be ready for the next login
loginBackStack.clear()
loginBackStack.add(LoginKey)
And your logout code is
user = null
// Reset the back stack for when
// the user logs in
backStack.clear()
backStack.add(HomeKey)Ian Lake
02/27/2026, 9:47 PMursus
02/28/2026, 4:07 AMIan Lake
02/28/2026, 4:10 AMursus
02/28/2026, 4:12 AMIan Lake
02/28/2026, 4:14 AMursus
02/28/2026, 4:16 AMIan Lake
02/28/2026, 4:18 AMursus
02/28/2026, 4:21 AM