Compose question. Once user authenticates, how do ...
# compose
k
Compose question. Once user authenticates, how do I remove authentication compose screens to not be in stack anymore? Multiple activities (e.g. AuthenticationActivity, ContentActivity) ?
c
The answer from Ian Lake hasn't changed at all from the recommendations he puts forward in the docs and also this video.

https://youtu.be/09qjn706ITA?t=285â–¾

I will admit that it still tripped me up big time in the compose world, and I'm definitely looking for more help understanding if I'm doing it correctly. Here is a repo of mine where I have a very simple sign in example that doesn't work: https://github.com/ColtonIdle/ComposeSignInSample I did get a PR from @zhuinden that fixes all of my issues though. So you can use that too if you want?
To answer your question though
Once user authenticates, how do I remove authentication compose screens to not be in stack anymore? Multiple activities (e.g. AuthenticationActivity, ContentActivity) ?
Basically your starting location should always be the "main" screen... not the "sign in" screen. When your main screen detects that a user is not logged in, then you navigate them to the sign in screen. Then when sign in is complete... you pop sign in. Leaving the user where they "originally" started (the "main" screen). Ian basically says that this is the recommended approach because then deep links work out really nicely. Imagine being deep linked to some really deep part of your app. But the user is not logged in... they log in... then they go back to where they came from!
n
I have also followed this suggestion and have found it works quite well. In our case navigation to login happens due to an event flow in a ViewModel, which pushes the login screen onto the stack, and once logged in, the login screen is simply popped. The ViewModel then continues to load data.
c
Yeah. It seems to work pretty well. I still get tripped up over how to actually call that event to go to SignIn screen and when to actually pop it off (as you can see in my broken 100 line example)
z
technically i made the stack be popped as you navigate. currently the stack is not preserved when you log in with log in and get forcibly logged out 🤔
c
Yeah, your approach is fine when popping, but I was still considering what to do if I wanted to keep the stack.