You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So, i started to do a little digging while trying to get a grip about Facebook integration and found out that one main issue is that the boilerplate does not have any (sane) logic for creating a local user.
This is the intended logic for creating a local user, any user creation has to be made by an authenticated user with two steps.
One creating the user with a POST to /User
Do an /auth/local/connect request with a password
Number 1 is pretty straightforward, number 2 gets tricky, because the Passport.protocol.local.connect requires a User model to be attached to the request object. This is not done anywhere.
One way of creating this logic is adding a custom register method in AuthController, attach the newly created user to the request object and call the Passport service. But the Passport Service looks for params like :provider and :action, overriding these params with hardcode seems hacky.
So this is what i managed too cook up. Opinions? Worth making a PL on?
//Add this in the beginning of AuthController.js
var actionUtil = require('../../node_modules/sails/lib/hooks/blueprints/actionUtil');
register: function(req, res){
var data = actionUtil.parseValues(req);
User.create(data).exec(function(err, user){
if(err) return res.negotiate(err);
if(!user) return res.notFound("User not found"); //This should never happen
req.user = user;
req.params.action = "connect";
sails.services['passport'].callback(req,res,function(err, user){
if(err) return res.negotiate(err);
res.ok(user);
});
});
},
So, i started to do a little digging while trying to get a grip about Facebook integration and found out that one main issue is that the boilerplate does not have any (sane) logic for creating a local user.
This is the intended logic for creating a local user, any user creation has to be made by an authenticated user with two steps.
Number 1 is pretty straightforward, number 2 gets tricky, because the Passport.protocol.local.connect requires a User model to be attached to the request object. This is not done anywhere.
One way of creating this logic is adding a custom register method in AuthController, attach the newly created user to the request object and call the Passport service. But the Passport Service looks for params like :provider and :action, overriding these params with hardcode seems hacky.
So this is what i managed too cook up. Opinions? Worth making a PL on?
Dont forget to add this in routes.js
The text was updated successfully, but these errors were encountered: