How can I handle deep links in jetpack compose when logged out

Viewed 267

I have an app where the user can be logged in or logged out and there are some screens which are only available in loggedInState which are accessed through deep links.

If the user is logged out and opens the app through a deeplink he should be directed to the login screen - login - and then be directed to the deeplink.

I can get this to work if the login screen is not a part of the navHost

if (!loggedIn) {
  LoginScreen(loginViewModel = hiltViewModel() )
} else {
  AppNavHost()
}

The problem in this case is that the Activity somehow gets recreated (I think because navController.handleDeepLink(intent) is being called) and the splashScreen (on phones < Android 12) is being showed twice - when opening the app and after success login.

So then I tried making LoginScreen a composable destination in AppNavHost - which removed the double splash screen - but now the deeplink is processed before the user is logged in.

0 Answers
Related