accounts-js / accounts

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

Add `userCollectionName` to `Mongo` object in `@accounts/mongo` or fix precedence in `@accounts/database-mongo-password` #1237

Open orenteriab opened 2 years ago

orenteriab commented 2 years ago

The property userCollectionName is not part of the Mongo options in the package @accounts/mongo.

I'm using:

 "@accounts/mongo": "^0.34.0",
 "@accounts/password": "^0.32.0",

I even get the error on TS end, that userCollectionName is not part of Mongo object: Screen Shot 2022-09-12 at 12 38 19

Screen Shot 2022-09-12 at 12 39 00

Although, the above code runs perfectly, I get that error from TS.

I think, in case you don't want to expose userCollectionName in Mongo object of @accounts/mongo, the precedence for it should be: 1.- userCollectionName in options param. 2.- collectionName in options param. 3.- userCollectionName in defaultOptions.

Here's the current code: https://github.com/accounts-js/accounts/blob/ff983b8f9603f6295f2b7c9830a7926bc36e81c4/packages/database-mongo-password/src/mongo-password.ts#L81-L85

My suggestions would be something like:

constructor(options: MongoServicePasswordOptions) {
    this.options = {
      ...defaultOptions,
      userCollectionName: options.userCollectionName ||
        options.collectionName || defaultOptions.userCollectionName,
      ...options,
      timestamps: { ...defaultOptions.timestamps, ...options.timestamps },
    };

Thanks in advance.