Overriding Accounts.config({}) on client!

Hello there!

I am trying to overwrite Accounts.config() on the client. What I am trying to achieve? I need toggle forbidClientAccountCreation True/falsr from an admin panel.

I have tried calling directly from client but nothing happens, also I added a meteor method to call Accounts.config() server-side.

Any advice on this?

Regards!

Can you describe in more detail the method and where the code is run?

Looking at the docs, AccountsCommon#config(options) should be run on both server and client.
So my guess is that you should run it in a method which runs on both

What I am trying to achieve is to prevent new signups. I want to do it from my “admin dashboard”.

I already call server-side Accounts.config({ forbidClientAccountCreation: true }); so I can prevent new signups.

I need to toggle this value. So I am trying to achieve something like this:

Accounts.config({ forbidClientAccountCreation: !Accounts.config.forbidClientAccountCreation }), I new to find a way to get the actual value of Accounts config to toggle true/false.

edit:

Accounts.config({
forbidClientAccountCreation: !Accounts._options
.forbidClientAccountCreation
});

This is the way to solve this, the problem is that you can call/set the value just one time! so I can’t toggle true/false as many times as I want.

Error: Can’t set forbidClientAccountCreation more than once

I nee to call this method more than once!

It seems that you could just toggle the value in Accounts._options.forbidClientAccountCreation directly.

Meteor.methods({
    'toggle-signups-on-client'(){
        Accounts._options.forbidClientAccountCreation = !Accounts._options.forbidClientAccountCreation
    }
});

Detail:

If you go for a quick dive in the accounts code:

// set values in Accounts._options
    _.each(VALID_KEYS, function (key) {
      if (key in options) {
        if (key in self._options) {
          throw new Error("Can't set `" + key + "` more than once");
        }
        self._options[key] = options[key];
      }
});

You can see that the Accounts.config({ ... }); method just assigns the value directly to this._options

And looking at accounts-password:

      // createUser() above does more checking.
      check(options, Object);
      if (Accounts._options.forbidClientAccountCreation)
        return {
          error: new Meteor.Error(403, "Signups forbidden")
};

It also checks the Accounts._options.forbidClientAccountCreation value directly.

Same goes for accounts-ui-unstyled:

showCreateAccountLink: function () {
    return !Accounts._options.forbidClientAccountCreation;
},

So changing the value directly should do what you want