Created
July 16, 2015 05:51
-
-
Save Shekharrajak/92fed7bf09a4c5cb1814 to your computer and use it in GitHub Desktop.
For the tutorial on medium.com : passportJS auth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* AuthController | |
* | |
* @description :: Server-side logic for managing auths | |
* @help :: See http://sailsjs.org/#!/documentation/concepts/Controllers | |
*/ | |
var passport = require('passport'); | |
module.exports = { | |
_config: { | |
actions: false, | |
shortcuts: false, | |
rest: false | |
}, | |
login: function(req, res) { | |
passport.authenticate('local', function(err, user, info) { | |
if ((err) || (!user)) { | |
return res.send({ | |
message: info.message, | |
user: user | |
}); | |
} | |
req.logIn(user, function(err) { | |
if (err) res.send(err); | |
return res.send({ | |
message: info.message, | |
user: user | |
}); | |
}); | |
})(req, res); | |
}, | |
logout: function(req, res) { | |
req.logout(); | |
res.redirect('/'); | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment