node.js - Session and Login User data with Node and AngularJS -
i need know if authentication , session management method right.
i using session management when receive successful auth. node server. store user data(without trace of pass.) in $window.sessionstorage , if user marked rememberme(checkbox), store data in $window.localstorage too.
through able data in different controllers. though read somewhere session implementation @ server(nodejs) side possible. not sure how use session along jsontoken authentication.
i using https://jasonwatmore.com/post/2015/12/09/mean-stack-user-registration-and-login-example.aspx learning example not understand it.
/app/app.js
why in run() method ?
// add jwt token default auth header $http.defaults.headers.common['authorization'] = 'bearer ' + $window.jwttoken;
and this:
// manually bootstrap angular after jwt token retrieved server $(function () { // jwt token server $.get('/app/token', function (token) { window.jwttoken = token; angular.bootstrap(document, ['app']); }); });
/controllers/app.controller.js
// use session auth secure angular app files router.use('/', function (req, res, next) { if (req.path !== '/login' && !req.session.token) { return res.redirect('/login?returnurl=' + encodeuricomponent('/app' + req.path)); } next(); }); // make jwt token available angular app router.get('/token', function (req, res) { res.send(req.session.token); }); // serve angular app files '/app' route router.use('/', express.static('app'));
so using session server-side jwt kind of defeats purpose of using jwt. jwt's awesome in number of ways, 1 of ways great, regardless server intercepts request, can verify user.
if put in session, have make sure client keeps going same server session saved in memory on machine. there plenty of ways around that, again kind of defeats purpose of json web token.
what did authentication angular/node/jwt passed jwt in header every time, , middleware intercepted with:
req.header.whatever_my_tokens_name_is
Comments
Post a Comment