使用 accounts-ui 包创建用户时如何添加 user.profile? [英] How can I add a user.profile when creating a user with the accounts-ui package?

查看:27
本文介绍了使用 accounts-ui 包创建用户时如何添加 user.profile?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将以下代码添加到accounts-ui 包中,以便在创建用户时创建配置文件?

How do I add the following code to the accounts-ui package so that a profile is created at the time the user is created?

    if (options.profile) 
    {
      user.profile = options.profile;
    }

如果帐户-ui 表单无法更改,是否可以在创建帐户时向配置文件添加一个空对象?

If the accounts-ui form cannot be changed would it be possible just to add an empty object to the profile at the time the account is created?

大概是这样的:

user.profile = {};

我在packages"目录中寻找这个包,但是没有找到,为什么没有?我认为这段代码可以很容易地进行任何必要的修改.

I was looking for this package in the "packages" directory but didn't find it, why is it not there? I thought this code would be easily available for any necessary modification.

对此的任何建议都会很棒.

Any advice on this would be great.

提前致谢:)

推荐答案

无需向任何包添加任何内容.Accounts 包中提供了一个钩子,该钩子在创建用户时运行.Accounts.onCreateUser 您可以使用它来填写用户文档的默认值.您以您希望保存的状态返回用户对象.

There's no need to add anything to any package. There is a hook available from the Accounts package that is run whenever a user is created. Accounts.onCreateUser You can use it to fill out default values for the user document. You return the user object in the state you want it to be saved.

它应该在服务器上运行.例如,创建文件 server/usersetup.js 并添加以下代码.

It should be run on the server. For example, create the file server/usersetup.js and add the following code.

Accounts.onCreateUser(function(options, user) {
    if (! options.profile) options.profile = {};
    options.profile.artist = true;
    options.profile.reputation = 100;
    options.profile.someObject = {a: [], b: {}};

    user.profile = options.profile;
    return user;
});

这是文档.

这篇关于使用 accounts-ui 包创建用户时如何添加 user.profile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆