[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
- [SOLVED] OAuth With Google & Flutter
Hi all, I'm trying to sign in with google and it all goes swimmingly until the call back. I get a new user created on the appwrite dashboard however the flutte...
- Realtime with multiple connections
I need the Realtime on multiple Collections for diffrent applicational logic. So my question is: Is there a way to have only 1 Websocket connection or do I need...
- Can't login or deploy functions in Appwr...
Hello, since i updatet to the appwrite cli 6.1.0 i can't login or deploy functions with the cli. When i call the command: "appwrite get account --verbose" i ge...