Skip to content

Instantly share code, notes, and snippets.

@thejh
Forked from seivan/gist:1103042
Created July 24, 2011 20:28
Show Gist options
  • Save thejh/1103067 to your computer and use it in GitHub Desktop.
Save thejh/1103067 to your computer and use it in GitHub Desktop.
protect = (req, res, next) ->
console.log "I don't even get here"
req.user = if req.isAuthenticated() then "YES" else "NO"
if req.isAuthenticated()
next()
else
req.authenticate ["twitter"], (error, authenticated) ->
if error
next new Error "Problem authenticating"
else
if authenticated == true
next()
else if authenticated == false
next new Error "Access Denied!"
app.get "/", protect, (req, res, next)->
res.send "SO YOU KNOW #{req.user}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment