Get the token returned by the backend after the user successfully logs in
userService.loginUser(user).then(
function(response) {
$cookies.put("token", response.token)
...
Then, how to carry this token when updating personal information?
token = $cookies.get("token")
console.log(token)
studentService.edit(token).save({studentId: $scope.student.id}, student,
function(response) {
console.log(response)
studentService
angular.module('app')
.factory('studentService', [
'$resource',
function($resource) {
return {
detail: function() {
return $resource('/api/student/:studentId/ ', {
studentId: '@studentId'
})
},
edit: function(token) {
return $resource('/api/student/:studentId/edit/ ', {
studentId: '@studentId'
},{headers: { 'auth-token': token }})
}
}
}
]);
I did this, but it still shows that the verification failed.
{withCredentials:true}
Popular science connectionThank you for the invitation. It is not convenient to send specific article links on mobile phones. Mainly to give you ideas.
After logging in, you need to bring a token with each request. Generally, this function is achieved by adding custom request headers, and AngularJS 1.x provides interceptors. It is also recommended that you also search for MDN CORS related information and $resource related documents.
There are many application examples of AngularJS 1.x and JWT abroad. It is recommended that you search on Google.
Use angularjs-jwt and add token to each request header. Reference: github address https://github.com/auth0/angu...