'How to store information about login in mobile application (offline or online)?
I made a simple application that allows you to take pictures offline and tag them. As soon as there is an internet connection, these data are sent to the server. I use a great backend solution - Appwrite. It works very well.
The last thing I wanted to do was user registration and login. The AppWrite SDK provides ready-made methods for creating user sessions, authentication. However, I have a problem how it should work if my application also works offline. E.g.
- I have an internet connection - I log in to the application - a session is being created.
- The next time you turn on the application, the login screen should not appear anymore. How is the application to know that a session is active and not to display the login screen if I do not have internet access?
- The same if I log out of the app when I do not have internet, the previous session will not be deleted.
I would be grateful for any advice on how to achieve this. To sum up - Should user login information be written somewhere local?
Solution 1:[1]
The simplest way is to use shared_preferences (offline) https://pub.dev/packages/shared_preferences and firestore (online) https://firebase.flutter.dev/docs/firestore/usage/
Solution 2:[2]
Storing the token or storing a boolean as userLogged into a localstorage would be the optimal choice for the application to identify user login. One simple solution for localstorage is using shared Preferences:https://pub.dev/packages/shared_preferences
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Evgen |
| Solution 2 | Hello world |
