1

I was wondering what was the best approach to take on implementing a function that will allow the user to keep him/her self logged in even after the application has been closed, by checking if the token allocated to user is still valid or not.

3
  • What would be the purpose of this? I don't quite understand. Do you want the user to NOT have to log in again when they restart the app? Commented Jun 14, 2018 at 18:33
  • Yes, to avoid to log in all the time Commented Jun 14, 2018 at 18:38
  • Then you'd need to persist some kind of token on your mobile device. That depends on the API you are talking to. I take it you are using OAuth or not? Take a look at flutter.institute/firebase-signin for a great way of doing this. Commented Jun 14, 2018 at 18:47

1 Answer 1

2

Upon successful login you can store the token either in the shared preferences using the shared_preferences package or in a more secure area using the flutter_secure_storagepackage.

When the user closes the app, to token will remain in the storage.

Then, on starting the app, you can get the token from the storage and validate it in the server. If the token continues to be valid you can grant access to the app, all of this transparently to the user.

If you use auth plugins like google_sign_in or firebase_auth almost all of this will be automatically integrated.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.