node.js - How to use PassportJS and JWT together? -
i'm building node.js app uses both passportjs , jwt since primary form of communication between front-end (angular spa) , back-end (node.js sails) via sockets. i'd allow registration both locally or using github, google, etc.
i've played sails-generate-auth , scoured hundreds of documentation , tutorials keep getting frustratingly stuck.
i'm using angular-sailsjs-boilerplate starting point, lacks registration endpoint non-local endpoints.
i created register endpoint in authcontroller:
register: function(request, response) { sails.models['user'].create(request.body).exec(function(err, user) { if (err) { response.json(err.status, {err: err}); return; } if (user) { response.json({user: user, token: sails.services['token'].issue(_.isobject(user.id) ? json.stringify(user.id) : user.id)}); } }); },
but seems app structured there passport records (credentials) , user records, , passport records used login.
does passport automatically generate user record or passport record, or must manually? how go doing when using 2 associated collections (credentials + users) @ registration?
does passport authenticated session management automatically?
does use of jwt void need passport sessions?
i'm of express noob , getting exhausted @ amount of code have regurgitate in order authentication working.
i tried following this example there seems no mention of encrypting password, , doesn't cover use case of 2-collection authentication.
is using 2 collections normal approach allowing multiple-method login?
Comments
Post a Comment