0

我不明白,我创建了这个方法

import { Accounts } from 'meteor/accounts-base';
import SimpleSchema from 'simpl-schema';
import { ValidatedMethod } from 'meteor/mdg:validated-method';

export const createUser = new ValidatedMethod({
  name: 'createUser',
  validate: new SimpleSchema({
    email: { type: String, optional: true },
  }).validator(),
  run({email}) {
    if (this.isSimulation) return true;
    ;

    const userId = Accounts.createUser({ email, password:'coucou' });

    return 'ok'
  },
});

当我调用它时:

import { createUser } from '../../../api/auth/methods.js'

createUser.call({ email: this.email.value }, function(err, data) {
    if(err){
      console.log('err: ', err);
    }else{
        console.log('data: ', data);
    }

我在服务器端有这个错误:

Error: A method named 'createUser' is already defined

所以,如果我改变了方法的名称是有效的。

但是,我想了解

1)为什么已经定义了'createUser'?

2)'createUser'默认方法来自哪里?

谢谢 ;-)

4

1 回答 1

1

我发现了这个问题,

当您这样做时,“createUser”来自“帐户密码包”:meteor add accounts-password

你可以检查你的应用程序

/MyAPPLICATION/.meteor/local/build/programs/server/packages/accounts-password.js

我们可以找到这个:

Meteor.methods({                                                                                                      
createUser: function (options) {  ...
于 2017-08-19T13:33:20.710 回答