Skip to content

Instantly share code, notes, and snippets.

@mikehostetler
Created May 27, 2014 13:35
Show Gist options
  • Save mikehostetler/19cc578b2f4ba2b9efa4 to your computer and use it in GitHub Desktop.
Save mikehostetler/19cc578b2f4ba2b9efa4 to your computer and use it in GitHub Desktop.
Res.json example
callback: function (req, res) {
passport.callback(req, res, function (err, user) {
//sails.log.debug("API -> Controllers->AuthControllers->Callback: Found our user, now lets log them in",user);
req.login(user, function (err) {
// If an error was thrown, redirect the user to the login which should
// take care of rendering the error messages.
if (err) {
var redirect = req.param('action') === 'register' ? '/#user/register' : '/#user/login';
if(req.wantsJSON === true) {
res.json(err.status_code || 403,{
message: "Authentication Failed, Redirect to "+redirect,
redirect: redirect,
err: err
});
}
else {
res.redirect(redirect);
}
}
// Upon successful login, send the user to the homepage were req.user
// will available.
else {
if(req.wantsJSON === true) {
res.json({ message: "Success!", user: req.user });
}
else {
res.redirect('/');
}
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment