gpt4 book ai didi

javascript - Meteor:尝试向用户配置文件 Accounts.onCreateUser() 添加另一个字段;

转载 作者:行者123 更新时间:2023-11-28 06:51:43 24 4
gpt4 key购买 nike

基本上尝试通过在其配置文件对象中为其提供一个名为 sid 的额外字段来修改刚刚创建的用户。我在 server.js (服务器代码)上运行它

Accounts.onCreateUser(function (options, user) {      
Meteor.users.update({_id: user._id}, {$set: {"user.profile.sid": [post.content]}});
});
console.log(JSON.stringify(user));

但是,用户对象在其输出中不显示 sid 字段。我是在错误的位置执行此操作还是我的代码错误?

最佳答案

From the docs

The function you pass will be called with two arguments: options and user. The options argument comes from Accounts.createUser for password-based users or from an external service login flow. options may come from an untrusted client so make sure to validate any values you read from it. The user argument is created on the server and contains a proposed user object with all the automatically generated fields required for the user to log in, including the _id.

The function should return the user document (either the one passed in or a newly-created object) with whatever modifications are desired. The returned document is inserted directly into the Meteor.users collection.

所以你的代码应该是:

Accounts.onCreateUser(function (options, user) {      
user.profile.sid = [post.content];
return user;
});

However be aware that anything in the user.profile object can be changed by your users .

profile: an Object which the user can create and update with any data. Do not store anything on profile that you wouldn't want the user to edit unless you have a deny rule on the Meteor.users collection.

关于javascript - Meteor:尝试向用户配置文件 Accounts.onCreateUser() 添加另一个字段;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32899227/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com