Code Monkey home page Code Monkey logo

Comments (14)

jaredhanson avatar jaredhanson commented on May 22, 2024 28

Fixed!

You can now invalidate an existing login session by setting user to false or null when calling done inside deserializeUser.

passport.deserializeUser(function(obj, done) {
  done(null, false);  // invalidates the existing login session.
});

Most ORMs set the result to null if the record wasn't found, as is the case with Mongoose. So, this will work as expected if you are deleting user records while they have an active session. In that case, findById sets user to null, which is passed through to Passport and the session will be invalidated.

passport.deserializeUser(function(id, done) {
  User.findById(id, function (err, user) {
    done(err, user);
  });
});

This is fixed in [email protected], which has just been published to the npm registry.

from passport.

cmwelsh avatar cmwelsh commented on May 22, 2024 7

I would note in the documentation that you have to return null or false. I tried returning undefined instead of null and came here through Google.

from passport.

tjwebb avatar tjwebb commented on May 22, 2024 6

A world where null and false are the same but are not the same as undefined makes no sense. The following are true facts of Javascript:

null == false == undefined
null !== false !== undefined

Inventing your own truth table where null == false != undefined makes things unnecessarily confusing.

from passport.

bengotow avatar bengotow commented on May 22, 2024 3

Just a heads up for folks stumbling across this—it turns out TypeORM returns undefined and not null. You should do something like (await User.findOne({where: {id: obj.id}})) || false for Passport to work properly.

from passport.

jaredhanson avatar jaredhanson commented on May 22, 2024

Agreed. I'm leaning towards option 1 as the proper fix.

from passport.

mwawrusch avatar mwawrusch commented on May 22, 2024

strong +1 for one.

from passport.

ktmud avatar ktmud commented on May 22, 2024

+10086 for this issue...

from passport.

jwyuan avatar jwyuan commented on May 22, 2024

At least allowing the developer to handle the error would be key. +1 for at least exposing that.

from passport.

EvHaus avatar EvHaus commented on May 22, 2024

+1 on this. Is there a workaround for the issue right now?

from passport.

thiagomagro avatar thiagomagro commented on May 22, 2024

Hello guys, any idea when this will be fixed?

from passport.

orangenotorange avatar orangenotorange commented on May 22, 2024

I'm having this exact same issue on version 0.1.12 with passport-facebook.

from passport.

chmanie avatar chmanie commented on May 22, 2024

Thank you! This should definitely find it's way into the documentation.

from passport.

Luchooo avatar Luchooo commented on May 22, 2024

This working for me, put the next following commands in your terminal:
redis-cli
select 1
FLUSHALL

from passport.

mifi avatar mifi commented on May 22, 2024

created PR to fix undefined problem #975

from passport.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.