簡體   English   中英

Accounts.createUser中的流星異步調用

[英]Meteor asynchronous call within Accounts.createUser

在注冊新用戶之前,我需要刪除前一封電子郵件,並查詢API以將更多信息作為產品需求填入User。

不幸的是我無法實現,這是我從服務器得到Exception while invoking method 'createUser' Error: insert requires an argument

到目前為止,我所做的是:

客戶:

Accounts.createUser({ email, password, profile: { something } }, (err) => {
  if (err) {
    console.error(err2.reason);
  }
  history.replace('/account');
});

服務器:

Accounts.onCreateUser((options, user) => {
  Meteor.users.remove({ email: options.email }, () => {
    try {
      const res = request.postSync(authenticate, {
        method: 'POST',
        json: true,
        body: {
          email: options.email,
          password: options.profile.password
        }
      });

      if (res.response.statusCode < 300) {
        const newUser = user;
        newUser.profile = {};
        newUser.profile.user_id = res.body.response.user_id;
        newUser.profile.token = res.body.response.token;
        return newUser;
      }

      throw new Meteor.Error(res.response.body.error.message);
    } catch (err) {
      throw new Meteor.Error(err.message);
    }
  });
});

我做錯了什么? 謝謝

Accounts.onCreateUser文檔中

該函數應返回用戶文檔(無論是傳入的文檔還是新創建的對象),並且需要進行任何修改。 返回的文檔將直接插入Meteor.users集合中。

盡管您的函數未返回任何內容,但它僅使用某些函數作為第二個參數調用Meteor.users.remove() 不要忘記,流星調用在Meteor中是同步的,因此應如下所示:

Accounts.onCreateUser((options, user) => {
  Meteor.users.remove({ email: options.email });
  // do something else
  return user;
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM