我有一个奇怪的问题, 我创建了一个表单,它将新用户添加到数据库,它工作正常。流星 - 添加新用户,更改登录用户
现在的问题是,如果我使用“Alex”帐户登录,并且向数据库添加了“Leonard”,Leonard将成功添加,登录用户将从Alex更改为Leonard。
如何防止此更改?
UPDATE:
这里是我的代码:
Template.addingUser.events({
'submit #addUser': function (e, t) {
e.preventDefault();
Session.set('name', t.find('#name').value);
Session.set('email', t.find('#email').value);
Session.set('homeAddress', t.find('#homeAddress').value);
Session.set('pass', t.find('#pass').value);
Session.set('taxNo', t.find('#taxNo').value);
let userId = Accounts.createUser({
username: Session.get('name'),
password: Session.get('pass'),
email: Session.get('email'),
profile: {
homeAddress: Session.get('homeAddress'),
}
}, function (err) {
if (err)
console.log(err);
else
console.log('It worked...');
});
}
});
更新1.1
我试图用Accounts.onCreateUser
功能。用户已成功添加,但当前登录的用户将在添加后注销。
这里是我的代码:
客户:
var options = {
username: t.find('#name').value,
password: t.find('#pass').value,
email: t.find('#email').value,
profile: {
homeAddress: t.find('#homeAddress').value,
}
};
Meteor.call('createUser', options);
服务器:
Meteor.methods({
employeeAddition: function(options){
Accounts.onCreateUser(function(options, user) {
if (options.profile)
user.profile = options.profile;
});
var userId = Accounts.createUser();
},
});
如何防止以后新用户注销当前用户被添加?
请出示您使用添加新用户的代码。 –
@MichelFloyd我更新了这个问题:) –