【问题标题】:How to avoid that Accounts.onCreateUser overwrites users.profile?如何避免 Accounts.onCreateUser 覆盖 users.profile?
【发布时间】:2015-05-15 06:47:31
【问题描述】:

在客户站点上,我有一个 extraSignupField -> 名称。这存储在 users.profile.name 中。代码如下:

Meteor.startup(function() {
  Accounts.ui.config({
  passwordSignupFields: 'EMAIL_ONLY'
});

AccountsEntry.config({
  homeRoute: '/',
  dashboardRoute: '/dashboard',
  profileRoute: '/profile',
  language: 'de',
  showSignupCode: false,
  extraSignUpFields: [{
    field: "name",
    label: "Name",
    type: "text",
    required: true
  }]
 });
});

在我运行 onCreateUser 的服务器站点上,这会被触发,但它只设置那里提到的值。当 onCreateUser 就位时,不会创建 users.profile 条目。

这是服务器代码:

Meteor.startup(function() {
  AccountsEntry.config({
    signupCode: null
});

Accounts.onCreateUser(function (options, user) {
    user.username     = options.email;
    return user;
    });

});

我的目标是保留来自 users.profile 和用户名条目的数据。不幸的是,我被困在了这一点上。

非常感谢 迈克尔

【问题讨论】:

    标签: meteor meteor-accounts


    【解决方案1】:

    当您编写自己的 Accounts.onCreateUser 时,它会覆盖默认值。默认情况下,options.profile 被复制到 user.profile。您可以通过在您自己的函数版本中制作此副本来恢复默认行为。您可以在 the docs 中看到这一点。

    Accounts.onCreateUser( function (options, user) {
        if (options.profile) user.profile = options.profile;
        user.username = options.email;
        return user;
    }
    

    【讨论】:

      猜你喜欢
      • 2021-11-10
      • 1970-01-01
      • 2013-06-02
      • 2020-05-18
      • 2022-01-22
      • 2017-08-08
      • 2019-06-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多