Created
August 4, 2011 20:01
-
-
Save kav/1126093 to your computer and use it in GitHub Desktop.
Connect-Auth Facebook middleware
This file contains hidden or 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
module.exports = (app) -> | |
ensureLogin: (req, res, next) -> | |
return res.end() unless req.session? | |
if req.session.fbid? | |
return next() | |
console.log req.isAuthenticated() | |
console.log 'Heading off to fb' | |
req.authenticate ['facebook'], (error, authenticated) -> | |
console.log 'back from fb' | |
unless authenticated then return res.end() | |
fbid = req.session.fbid = req.getAuthDetails().user.id | |
name = req.getAuthDetails().user.name | |
email = req.getAuthDetails().user.email | |
console.log "User Name: #{name} and Email: #{email}" | |
user = app.models.users.get(fbid) ? app.models.users.create id: fbid, name: name, email: email | |
user.set online: true | |
return next() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment