accounts-js / accounts

Fullstack authentication and accounts-management for Javascript.
https://www.accountsjs.com/
MIT License
1.5k stars 141 forks source link

Accountsjs mongo package not respecting collection name #1155

Closed Ryiski closed 3 years ago

Ryiski commented 3 years ago

Bug report

Describe the bug

I've created to intense of mongo one has the default collection name user the other drivers and when a user is created with drivers it ends up creating in user collection.

To Reproduce

const userDB = new Mongo(db, {
    collectionName: 'users',
    convertUserIdToMongoObjectId: true,
  });

  const driverDB = new Mongo(db, {
    collectionName: 'drivers',
    convertUserIdToMongoObjectId: true,
  });

  await Promise.all([driverDB.setupIndexes(), userDB.setupIndexes()]);

  await userDB.createUser({
    email: 'user@user.com',
    password: 'userDemo123'
  });

  await driverDB.createUser({
    email: 'user@user.com',
    password: 'userDemo123'
  });

Expected behavior

It should create the users in the given collection name

Screenshots

Nop

System information

    "@accounts/graphql-api": "^0.33.0",
    "@accounts/mongo": "^0.33.0",
    "@accounts/password": "^0.32.0",
    "@accounts/server": "^0.33.0",

Additional context

I've dug into to the model package and It seems like in the file node_modules/@accounts/mongo/lib/mongo.js we need to pass a key of userCollectionName with the collection name to

this.servicePassword = new mongo_password_1.MongoServicePassword({ ...this.options, userCollectionName: this.options.collectionName, database: this.db });
this.serviceMagicLink = new mongo_magic_link_1.MongoServiceMagicLink({
            ...this.options,
            userCollectionName: this.options.collectionName,
            database: this.db,
        });

Once i added them they are working fine

pradel commented 3 years ago

Good catch, pr welcome for the fix :)

Ryiski commented 3 years ago

@pradel I can make a PR but im not sure how i would write a test for it

pradel commented 3 years ago

It's fine to just have the fix for now :)

Ryiski commented 3 years ago

Cool created a PR @pradel