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

User serialization / deserialization #87

@dfliess

Description

@dfliess

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions