Skip to content

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

@orenteriab

Description

@orenteriab

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:

this.options = {
...defaultOptions,
...options,
timestamps: { ...defaultOptions.timestamps, ...options.timestamps },
};

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions