Reputation: 447
I'm developing a quite big smartphone app and I chose to use flutter. I've only played around to and made some small and easy app. Now I'm facing the real world and things are becoming pretty difficult.
I come from react so I thought the best way to implement it was using redux with this Boilerplate but I really can't even fetch and display anything.
My goal: User login -> I save the token in the store and then use it for any request i need to make.
Do you know any other way to achieve my goal?
Upvotes: 2
Views: 5863
Reputation: 3598
You can use JWT
and create a token in the server when the user logins for the first time. after that you can save that token on device (and also the server) and add it to the http requests you do in future calls:
Future<http.Response> fetchPost() {
return http.get(
'https://jsonplaceholder.typicode.com/posts/1',
// Send authorization headers to your backend
headers: {HttpHeaders.authorizationHeader: "Basic your_api_token_here"},
);
}
You'll be able to log the user in, in future app runs with the token you have in your db.
more about the request here: https://flutter.io/cookbook/networking/authenticated-requests/
Upvotes: 3