I am using Laravel for my back end and Flutter for my front end.
When the token is stored, I use my local storage:
localStorage.setString('token',json.encode(body['access_token']));
This works fine. The token is stored as expected. But when I try to get it back from localStorage
using:
token = localStorage.getString('token');
Then the token will be returned in the following format:
> \"eyJ0eXAiOiJKV1[...]a0\"
where the backslash located in the start and finish of the token which were NOT supposed to be there.
How can I remove them before using it for a call on my backend?
However, before the store event, I use DebugPrint() to "see" that the token is returned from my call to Laravel.
With debugPrint(), I get the proper result of the token which looks like :
>"eyJ0eXAiOiJ[...]|"
I am using the method bellow to create a call to pass to my backend:
getData(apiUrl) async {
var fullUrl = _url + apiUrl;
await getToken();
return await http.get(Uri.parse(fullUrl), headers: _setHeaders());
}
the part with Bearer is now stored BUT some additional characters are added to it. More specifically, " on the start and on the end of my token string.
getData(apiUrl) async {
var fullUrl = _url + apiUrl;
token = await Network.getToken();
// debugPrint(token);
return await http.get(Uri.parse(fullUrl), headers: _setHeaders());
}
_setHeaders() => {
'Content-type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer $token',
};
}