[SOLVED] Listen to account (session) changes, and logging in when offline.
- 1
- Flutter
- Realtime
- Accounts
Hello, I am struggling to find a way to find out in real time whether a account(session) is active or not, mainly to redirect users automatically to login screen, or allow access to other modules of the app.
I am using go_router for navigation, and I would like to have it take caree to redirect, by listening to changes on the account(session).
On the other hand I need to allow access to the app to users, even when the app is offline. The optimal thing would be that if the user was already authenticated before going offline, then just keep that session, and allow access. If the user has never accessed the app before going offline, the guest login option should be available to allow access.
Is any of this possible, what would be the way to use the sdk to achieve it? The app would be used on all platforms available for Flutter. Thanks in advance.
The way we typically handle this is to call account.get() on app start. If that doesn't throw an exception, the user has a valid session and can proceed. If there is an exception, redirect the user to the login page.
For offline, you'll have to maintain some sort of offline flag. For example, you can store in shared preferences a true or false for if they logged in already or not
Thanks @Steven.
Will the account.get() work if the device is offline?
No, my second paragraph was for offline
I understand, but then will I be able to get the logged in user if the connection drops?
Of course not
thank you @Steven
@OppositeDragon can we set this issue as solved?
yes, thank you!
[SOLVED] Listen to account (session) changes, and logging in when offline.
Recommended threads
- Weird permission failure
when creating an account I use following methods: ``` Future<void> register(String email, String password, String username) async { final user = await accoun...
- Flutter Android oAuth is no more working
I currently don't get the oAuth login to work in flutter android. it works on ios and on web. but when try to use it on Android, i get to the point where the ca...
- I'm experiencing a critical bug on Appwr...
Hey <@870607367597850624> team / support š I'm experiencing a critical bug on Appwrite Cloud that's blocking my production Flutter app. I've already filed GitH...