DennyHiu
DennyHiu

Reputation: 6110

How to implement JSON web Token in Angular-Express app?

I have a standard Nodejs + Express + Angular application. After I read several tutorial about JSON Web Token from here, here and several more, I tried to implement JWT authentication in my application using this following procedures:

My question is: How to send custom header with <a> ? Or is it the "correct" way to implement it ? Or someone have better solution ?

Upvotes: 0

Views: 255

Answers (1)

yazaki
yazaki

Reputation: 1632

You could send custom http header by using $http service in a ng-click handler or something. If it is laborious to add ng-click to every A tag, you could write your directive code in which you can bind click handler automatically to every A tag and use $http service in click handler.

Directive code is something like this.

.directive('a', function($http){
    return {
        restrict: 'E',
        link: function(scope, element, attrs) {
            element.bind('click', function(){
                console.log("You can use $http service.", $http);
            });
        }
    }
})

jsfiddle is here.

Upvotes: 0

Related Questions