Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

User serialization / deserialization #87

Open
dfliess opened this issue May 7, 2019 · 0 comments
Open

User serialization / deserialization #87

dfliess opened this issue May 7, 2019 · 0 comments

Comments

@dfliess
Copy link

dfliess commented May 7, 2019

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)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant