Home > Enterprise >  flutter secure storage how to store bearer token?
flutter secure storage how to store bearer token?

Time:07-20

I try to store bearer access token to flutter secure storage. But I only able to access to body part details. i print jsonDecode(res.body) i can get all the details. but i write await storage.write(key: "token", value: data["access_token"]); i get null return.

How can I access to Body>Data > Accesstoken to get token and storage into secure storage?

                         var data = jsonDecode(res.body);
                         
                                            
                          await storage.write(key: "token", value: data["access_token"]);
                        
                         
                        
                          Navigator.pushReplacement(
                              context, SlideRightRoute(page: ooww()));
                          break;

enter image description here

CodePudding user response:

The token is inside the key data. So you have to use

var data = jsonDecode(res.body);              
await storage.write(key: "token", value: data['data']["access_token"]);
                        
  • Related