https://kotlinlang.org logo
#compose
Title
# compose
u

0xf1f1

03/01/2024, 1:49 AM
where is the best place to do authentication checks and redirect to login if a user's session has expired ? The intuition is to do the checks in every screen but that seems like a lot of repetitive code,
s

Sean Proctor

03/01/2024, 1:17 PM
How often does a user's session expire? Are you doing something extremely sensitive where they need to frequently re-enter their credentials? Normally, you should use a refresh token to not bother your user. In that case, I would make the check when you try to access whatever resource they need to be authenticated for, because you're going to need to handle that case regardless. You might also want to be proactive and monitor the access token at the top level of your app and refresh it on expiry or redirect the user to re-login when the refresh fails. One issue here is that the network may be flaky and the refresh could be retried. You'll need to decide what to do in that situation.
z

Zach Klippenstein (he/him) [MOD]

03/01/2024, 5:32 PM
This isn’t really a compose question but an architecture/design one