0
在註冊新用戶之前,我需要刪除前一個包含該電子郵件的用戶,並查詢API以將更多信息填入用戶作爲產品需求。Accounts.createUser中的流星異步呼叫
不幸的是我無法實現它,這是我從服務器得到的錯誤: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);
}
});
});
我做錯了嗎?感謝
真棒,好知道DB調用是同步的。謝謝 –