The reason you are not able to achieve this is tha...
# flutter
m
The reason you are not able to achieve this is that you have set your login page as the default/initial route in your routing mechanism (whatever package you use to manage it). So even if the session is still there, tha app loads the login page and lets you authenticate the user again. The way you can probably resolve this is to play with your routing mechanism a bit and implement something like a guard. Route guards are a feature in a lot of packages like beamer, go_router, vrouter, etc but most of them do not allow asynchronous API calls to check Auth status. You will have to do some crazy work around to set it up. Something like this: login route is initial route -> app launches and tried to navigate to login page which calls the route guard -> this guard checks the current Auth status of the user (you can store the last users credentials in the shered prefs) -> if the user is already authenticated then it "redirects" you to home page -> if not then you navigate to login page. If the user is already in the app, you can wrap the whole app inside a stream builder and check for Auth changes inside the stream.
20 Views