Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Node.js passport skips strategy

Node.js passport skips strategy


This coffee-script passport implementation looks just like the examples to me but fails every time and never prints "Trying out the strategy". I just get redirected to "/fail". I tried naming the Strategy as well as executing it in the (req, res, next) handler. I also verified that the form posted sent the username and password in those fields and tried renaming them with a mapping in the strategy according to the examples to no avail. Any tips on what I'm overlooking?

pass = require 'passport'
strat = require('passport-local').Strategy
exp = require 'express'
app = exp.createServer()

# Configure strategy
pass.use new strat (username, password, done) ->
    #Logic to find user
    console.log("Trying out the strategy")
    user = {nm:username,ps:password}

app.configure () ->
    app.use (req,res,next) ->
        console.log("GOT A REQ")
    app.use pass.initialize()

ops = { failureRedirect: '/fail' } '/auth', pass.authenticate('local',ops), (req, res, next) ->
    console.log "what about here"

app.listen 1337

Solution Modify express configuration:

app.configure () ->
    app.use exp.bodyParser() 
Problem courtesy of: ace


Turns out this problem was due to my ignorance of express. I was sending the username and password but wasn't parsing it - app.configure requires express.bodyParser() in order to utilize the strategies.

Solution courtesy of: ace


View additional discussion.

This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Node.js passport skips strategy


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription