I have Laravel endpoints. Login, Register and Home(where getData() will be working).
the register API and Login API is working fine but the problem is with the HomePage API where it will not ask for user details, it's a get method where it will return the details upon checking whether the user is logged-In or not.
var token;
_getKey() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
token = prefs.getString('key');
print("this is Key $token");
}
saveKey(String key) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString('key', key);
}
getData() async {
await _getCSRF();
await _getKey();
print(_setAuthHeaders());
String uri = "$baseUrlUser/user_bal";
try {
return await http.get(Uri.parse(uri), headers: _setAuthHeaders());
} catch (e) {
return e;
}
}
_setAuthHeaders() => {
'Accept': 'application/json',
'Connection': 'keep-alive',
'Authorization': 'Bearer $token',
};
result of hitting the endpoint in the browser.
Please help.
'Authorization': '$token;',
? There is:
at the end of the$token
. – Libavahttp
. – Hazenhttp
library – Libava