I want to increase restriction in my system.Then I used JWT token.then i preferred statellizer for the front-end.
once user log into the system.it will generate token like this
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InRlc3RAZ21haWwuY29tIiwiaWF0IjoxNDU1NzAzNTE5fQ.I6z8jlXx4H1R3gNOAnOysdI0qyeU01GAlnYWeQZKThs
But case is when user successfully log into the system.It will redirect to the dashboard but token did n't bind with the request.
other request are working properly only case in the dashboard.
login function in Controller
$scope.authLogin = function () {
$auth.login({
email: $scope.email, password: $scope.password
}).then(function(res){
//userService.setUser(res.data.user);
toastr.success('Successfully login ', 'Message', {
closeButton: true
});
window.location = '/dashboard';
}).catch(function onError() {
toastr.error('Invalid email/password combination.', 'Error', {
closeButton: true
});
});
};
routes file
'/login' : { view: 'static/login'},
'/signup' : { view : 'static/signup'},
'/' : { view: 'static/login' },
'GET /dashboard' : 'PageController.showDashboard',
policies file
'UserController':{
'*':['jwtAuth'],
authLog : true
// signUp : true
},
'PageController': {
'*': ['jwtAuth']
}
I want to make it like anyone can't access dashboard without token.I hope my question is clear.
Thanks
Way of I tried,That is wrong because when we called GET /dashboard function then could n't bind token with request.This method perfectly work with session.
I used following method.It work for me.This is more convenient to handle JWT with sails.
json-web-tokens-examples with sails