Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8052089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:27:41+00:00 2026-06-05T07:27:41+00:00

(updated code with serialization functions – still redirects to /failedRedirect) I’m trying to get

  • 0

(updated code with serialization functions – still redirects to /failedRedirect)

I’m trying to get simple username/password authentication going using the passport package, but failing. In the example below I’ve tried to verify that authentication works by basically always returning a valid authentication (regardless of what gets passed), but for some reason it fails and passport redirects to the failed login link.

If anybody could help me out in figuring out how to get this example to simply authenticate anything, I should be able to manage from there.

The code in coffeescript is:

express = require "express"
passport = require "passport"
LocalStrategy = require("passport-local").Strategy

passport.use(new LocalStrategy( (username, password, done) ->
  console.log "LocalStrategy invoked"
  done(null, {id: 1, name: "Marius"})
))

passport.serializeUser (user, done) ->
  done null, user

passport.deserializeUser (obj, done) ->
  done null, obj

app = express.createServer()

app.configure ->
  app.use express.bodyParser()
  app.use express.static("./public")
  app.use express.cookieParser("SOMESECRET")
  app.use express.session
    secret: "SOMESECRET"
    cookie:
      maxAge: 60000
  app.use passport.initialize()
  app.use passport.session()
  app.set "view", "./srv/views"
  app.set "view engine", "jade"

app.get "/login", (req, res) ->
  res.send "login page"

app.post "/login", passport.authenticate("local",
  failureRedirect: "/failedRedirect"
  successRedirect: "/successRedirect"
  failureFlash: true)

app.listen 8082

Solved: Ok, I believe there were a few reasons why I could not get it working. The serialize stuff may be one (I haven’t tested), but since Jared said they were needed, I’m leaving them in (he’s the author of Passport). The other confusion may be related to express versions and my confusion with npm. I believe I tested both the latest v2 of express, but I’ve also tested v3, which I am running now. For version three, you probably should check out the connect-flash module on Github as well, as some to the “flash” stuff which is used in Jared’s examples was moved out of express v3 (so the module puts it back in…). And finally, make sure you post using the proper named input names (username and password by default).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:27:42+00:00Added an answer on June 5, 2026 at 7:27 am

    It looks to me like you’re missing the necessary user serialization logic to establish a login session. If I add these two functions to the JavaScript code, it works:

    passport.serializeUser(function(user, done) {
      done(null, user);
    });
    
    passport.deserializeUser(function(obj, done) {
      done(null, obj);
    });
    

    You’ll want to serialize the users according to your needs. Details are at the bottom of this page: http://passportjs.org/guide/configuration.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay I have updated my code a little, but I am still not exactly
UPDATED: I have the following code, where I am trying to use returned JSON
I have updated code for ActiveX functionality which already installed on client(in their Windows
I updated my code with string dates created with new Date and added back
I updated my code like Andro wrote about to me: public class ZiiziiActivity extends
Okay I have updated my code quite a bit. I am getting a new
I've updated some code to use the Ajax Control toolkit 0911 beta and for
UPDATE I have updated my code in response to @MichaelRushton comments. I am now
I've updated my code here. I've put the range inside the unavailableDays function which
I ran some CUDA code that updated an array of floats. I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.