nickredmark / ooth

User identity/authentication/accounts management microservice for node.js
https://nmaro.github.io/ooth/
MIT License
605 stars 65 forks source link

User serialization / deserialization #87

Open dfliess opened 5 years ago

dfliess commented 5 years ago

I'm using ooth on an integrated express server with sessions stored on a Mongodb. In the documentation it's says

Securing a resources API If your API is provided by the same express app used by ooth, the user object will automatically be injected in the session. Nothing to do here.

but what I'm getting is not the real user object, just the user id.

So I suppose that I should change the passport serialize and deserialize to something like this:


passport.serializeUser((user, done) => done(null, user._id) );

passport.deserializeUser((userId, done) => {
    ooth.getUserById(userId)
    .then((user) => {
      done(null, user)
    });
  });

But as soon as I do that I start getting this error on any route:

Error: Argument passed in must be a single String of 12 bytes or a string of 24 hex characters
    at new ObjectID (/Users/dfliess/Develop/thb-api/node_modules/bson/lib/bson/objectid.js:59:11)
    at OothMongo.<anonymous> (/Users/dfliess/Develop/thb-api/node_modules/ooth-mongo/lib/index.js:22:51)
    at Generator.next (<anonymous>)
    at /Users/dfliess/Develop/thb-api/node_modules/ooth-mongo/lib/index.js:7:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/dfliess/Develop/thb-api/node_modules/ooth-mongo/lib/index.js:3:12)
    at OothMongo.getUserById (/Users/dfliess/Develop/thb-api/node_modules/ooth-mongo/lib/index.js:21:36)
    at Ooth.<anonymous> (/Users/dfliess/Develop/thb-api/node_modules/ooth/lib/index.js:93:33)
    at Generator.next (<anonymous>)
    at /Users/dfliess/Develop/thb-api/node_modules/ooth/lib/index.js:7:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/dfliess/Develop/thb-api/node_modules/ooth/lib/index.js:3:12)
    at Ooth.getUserById (/Users/dfliess/Develop/thb-api/node_modules/ooth/lib/index.js:92:36)
    at /Users/dfliess/Develop/thb-api/node_modules/ooth-user/lib/index.js:14:54
    at Generator.next (<anonymous>)
    at /Users/dfliess/Develop/thb-api/node_modules/ooth-user/lib/index.js:7:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/dfliess/Develop/thb-api/node_modules/ooth-user/lib/index.js:3:12)
    at ooth.registerAfterware (/Users/dfliess/Develop/thb-api/node_modules/ooth-user/lib/index.js:12:48)
    at Ooth.<anonymous> (/Users/dfliess/Develop/thb-api/node_modules/ooth/lib/index.js:316:36)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/dfliess/Develop/thb-api/node_modules/ooth/lib/index.js:4:58)