[SOLVED] Meteor Accounts.setPassword: Error: Match error: Failed Match.OneOf, Match.Maybe or Match.Optional validation

Hello,

We get this error in an old project we tried to upgrade.

What we did check:

  • Format of data we insert into the function (always String)
  • Recreated user to be sure (problem is on all users using this function)
  • Updates Meteor, Meteor Accounts and Meteor Password
  • Running “babel-compiler@7.10.4” and “babel-runtime@1.5.1”

Error:

 Exception while invoking method 'addRoleToNewUser' Error: Match error: Failed Match.OneOf, Match.Maybe or Match.Optional validation
     at check (packages/check/match.js:36:17)
     at packages/accounts-password/password_server.js:326:3
     at /Users/****/.meteor/packages/promise/.0.12.2.qp6glq.78er++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/meteor-promise/fiber_pool.js:43:40
  => awaited here:
     at Function.Promise.await (/Users/****/.meteor/packages/promise/.0.12.2.qp6glq.78er++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/meteor-promise/promise_server.js:56:12)
     at AccountsServer.Accounts.setPassword (packages/accounts-password/password_server.js:358:18)
     at MethodInvocation.addRoleToNewUser (server/methods/users/userMethods.js:166:13)
     at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1902:12)
     at getCurrentMethodInvocationResult (packages/ddp-server/livedata_server.js:772:38)
     at packages/meteor.js:365:18
     at Meteor.EnvironmentVariable.EVp.withValue (packages/meteor.js:1389:31)
     at packages/ddp-server/livedata_server.js:791:46
     at new Promise (<anonymous>)
     at Session.method (packages/ddp-server/livedata_server.js:739:23)
     at packages/ddp-server/livedata_server.js:603:43
 Sanitized and reported to the client as: errorClass [Error]: Match failed [400]
     at errorClass.<anonymous> (packages/check/match.js:91:27)
     at new errorClass (packages/meteor.js:718:17)
     at check (packages/check/match.js:36:17)
     at packages/accounts-password/password_server.js:326:3
     at /Users/****/.meteor/packages/promise/.0.12.2.qp6glq.78er++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/meteor-promise/fiber_pool.js:43:40 {
   isClientSafe: true,
   error: 400,
   reason: 'Match failed',
   details: undefined,
   errorType: 'Meteor.Error'
 }

Code:

... create user
const user = Meteor.users.findOne(userId);
const password = Random.secret(12);
Accounts.setPassword(String(user._id), String(password), false);

We got a fix! Good to know for everyone that has the same problem:
The third parameter should be an object. In previous versions, this could be a Boolean (there is only one option).

Fix:

Accounts.setPassword(user._id, password, {logout: false});
1 Like