Search code examples
fluttertokenaccess-token

Flutter-What is the point of using bearer-token or something


I read something like this: 1-Once a user logs in, you can generate a token and store it in MySQL database and share the same token with the response of login API. 2-Store the token using shared-preferences. 3-When a user opens the app, check if the token exists if it does, then send the token with all the APIs inside the request header which requires the user to be logged in.

But what is the point of using token if i was keeping it in database.Eventually this token related with userid and with this userid everthing can be reachable.So I want to ask why should I use some token to keep user loged in instead of user email or something.


Solution

  • Using token is much more secure and useable. Storing just token more secure becase in case of leak, the token can be revoked or something. On the other side storing user's username and password is security risk. Also, most of the services use tokens on their API's and there is no username+pass authorization. For example whole OAuth2 concept is built on top of this. In short, tokens are much more secure and flexible.