Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.12 New 'collection' option for Accounts does not permit the name 'users' for a remote collection #12610

Open
paulincai opened this issue May 3, 2023 · 5 comments
Labels
good first issue Good first issue or something that should is nice to do. hacktoberfest hacktoberfest issues for contribuition. Project:Accounts (in user apps)

Comments

@paulincai
Copy link
Contributor

paulincai commented May 3, 2023

server.js

import { UsersDB } from '../../api/collections/users/server/users'

Meteor.startup(() => {
  Accounts.config({
    loginExpirationInDays: process.env.LOGIN_EXPIRATION_IN_DAYS || 30,
    sendVerificationEmail: false,
    collection: UsersDB
  })
})

A console.log() right above the following line:

this.users = this._initializeCollection(options || {});

should print my configuration options but the object is empty because the configuration was not yet applied and options are not passed. This results in the creation of a local collection 'users'.
Further down in AccountsCommon, the config(options) is being applied however, if you want to connect to a remote collection named 'users' of another Meteor instance, you can't because the other collection should not have the name 'users':

if (options.collection && options.collection !== this.users._name && options.collection !== this.users) {...}

if (options.collection && options.collection !== this.users._name && options.collection !== this.users) {

@paulincai paulincai changed the title v2.12 New 'collection' option for Accounts not initialized v2.12 New 'collection' option for Accounts does not permit the name 'users' for a remote collection May 3, 2023
@paulincai
Copy link
Contributor Author

paulincai commented May 3, 2023

It also seems that this happens:

  1. In AccountsCommon a default collection is being initialized and this.users (Meteor.users) becomes this collection. (line 46)
  2. Accounts configuration is called on startup.
  3. In AccountsCommon the configuration is being applied (line 289) however, this.users (Meteor.users) remains assigned to the initial value from line 46.

Meteor.users should reflect the actual users collection while creating a local DB is not necessary.

For now I could just reinitialized Meteor.users with my new DB but that doesn't sound right:

export const UsersDB = new Meteor.Collection('otherUsers', { _driver })

Meteor.users = UsersDB
Meteor.users.attachSchema(User)

@Grubba27
Copy link
Contributor

Grubba27 commented May 3, 2023

Yeah, that does not sound correct.
Thanks a lot for reporting.

@Grubba27 Grubba27 added the good first issue Good first issue or something that should is nice to do. label May 3, 2023
@SamarthBagga
Copy link

SamarthBagga commented May 25, 2023

Hi @paulincai I think I may have a probable fix for your issue. But the problem is that I am unable to replicate the issue on my local environment. The fix is to replace a line in the "accounts_common.js"-
Could you replace-

if (options.collection && options.collection !== this.users._name && options.collection !== this.users) { this.users = this._initializeCollection(options); }

with this -

if (options.collection && options.collection !== this.users._name && options.collection !== this.users) { this.users = options.collection; }

and then try to run the server and do the same thing. If this does not work or if there is some other problem could you guide me as to how I can replicate this issue?

@mcorbelli
Copy link
Contributor

Any updates?

@nachocodoner
Copy link
Member

I faced a problem customizing the Users collection name in my projects.

When you designate a different name for your users collection using options.collection, the default indexes expected for the new collection aren't created, including those from the main accounts package and others. This likely occurs because Accounts.config occurs after Accounts constructor, similar to the other issues mentioned here. To address this, configuring the custom collection name, especially for index issues, should happen at the level of settings.json config of the package. Or completely change the code flow. In my case, I had to fork the package and directly modify the code for my app to simplify and focus on my app development.

These issues need attention. Is anyone available to tackle them now? Otherwise we'll address them later when we have more capacity on the core team.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good first issue or something that should is nice to do. hacktoberfest hacktoberfest issues for contribuition. Project:Accounts (in user apps)
Projects
None yet
Development

No branches or pull requests

6 participants