2๐
โ
You must pass the token as you Authorization header in every request where you access logged in content. You can do this by using $https default headers.
$http
.post('/api-token-auth/', {email: $scope.account.email, password: $scope.account.password})
.then(function(response) {
...
} else {
localStorage.setItem('myApp.token',response.token);
$http.defaults.headers.common.Authorization = 'Bearer ' + response.token
$state.go('dashboard');
}
...
You should also save this value in localstorage and set the default header in you apps run, so that when a user comes back yo your page they are already logged in. Like this:
angular.module('myApp').run(function($http) {
$http.defaults.headers.common.Authorization = 'Bearer ' + localStorage.getItem('myApp.token')
});
๐คErik Svedin
0๐
If you receive a token as a response, it means that the user is already logged in.
To use the token, you should add it as an http header for subsequent requests.
Authorization: JWT <your_token>
๐คRod Xavier
- [Answered ]-How to get attribute of a django model's foreign key object using getattr in python?
- [Answered ]-How to retrieve the field which triggered a hit for a elasticsearch query
Source:stackexchange.com