[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] curl error Number: 6 — function...
Hello, I invested a lot of time in this error in a fresh install of appwrite 1.8.1 and lasted until fix, this if for helping anyone that can have the same weird...
- android platform invaild origina
It happened today suddenly. Our app says invalid origin. And appwrite cloud says every time we tried to add the app to it: "param platformId" is not optional.
- Team invite - 500 error - no email
When executing ```dart await _repository.teams.createMembership( teamId: event.listId, roles: ['member'], email: event.email, url: 'xxxx', ); ``` I se...