Potato
Potato

Reputation: 539

How do i allow a user to stay logged in in flutter in the safest way?

I want a user to stay logged in after closing the app. I've heard of shared preferences but most of the examples are for things not as important as users' login credentials so is it possible to use that package for this? Furthermore, is that a safe way to go about this problem? Or should i allow google sign in, in order to keep them signed in? I'm generally unsure about how i should go about doing this and which is the safest way?

Upvotes: 0

Views: 249

Answers (1)

MrDumb
MrDumb

Reputation: 2178

There are multiple ways to go around this problem.

1) Keeping login Data on the client side

You can use Shared Pref. Once logged in you can save a value in shared Pref or in your db. When the user comes again you can check the value, if sharedpref says user is loggedIn, take user to HomeScreen else login screen.

2) Keeping login data on your server.

You can use a web API to make sure if user is loggedin. When user login for first time you can store loginStatus on server. when user kills app and come back again you check with an API. if user was loggedIn. If user was loggedIn, take user to HomeScreen else login screen.

3) Using third Party APIs

As you already mentioned Google Sign In. You can certainly leverage that. It is a powerful and clean API. But most importantly check it with your business requirement and compliance team.

Upvotes: 1

Related Questions