【问题标题】:Accounts.createUser doesn't save profileAccounts.createUser 不保存个人资料
【发布时间】:2015-04-17 17:01:35
【问题描述】:

我的server/fixtures.js 文件中有以下代码:

var userId = Accounts.createUser({
  username: "tester",
  email: "a@b.com",
  password: "foobar",
  profile: { name: "Max" }
});
var user = Meteor.users.findOne({_id: userId});
console.log(user.profile.name);

现在,当我运行 meteor 时,它会记录 undefined。我做错了什么?

【问题讨论】:

    标签: meteor accounts createuser


    【解决方案1】:

    我很确定我已经在某个地方定义了一个 Accounts.onCreateUser 回调来负责这个问题。我的错!

    【讨论】:

      【解决方案2】:

      我认为您需要使用 Meteors Publications & Subscriptions。检查这个link 了解更多信息。

      示例:

      if (Meteor.isServer){
        Meteor.publish('userdata', function() {   
          if(!this.userId) return null;
          return Meteor.users.find( this.userId );
        });
      }
      
      if (Meteor.isClient){
          Meteor.subscribe('userdata');
          console.log(Meteor.user());
      }
      

      【讨论】:

        【解决方案3】:

        所以,问题是console.log 在服务器上不可用(该文件根据Meteor 目录约定运行。)。如果您想登录到服务器控制台,您可以使用Meteor._debug(),它的工作方式与 console.log 相同。您可能还需要考虑将代码包装在 Meteor.startup(function() {}); 块中,以便它在服务器启动时立即运行。

        【讨论】:

        • console.log 在服务器上可用。您可以在运行流星服务器的窗口中看到输出。我自己回答了这个问题,我假设我在某处定义了一个 Accounts.onCreateUser 回调。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-01-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-28
        • 2023-03-28
        相关资源
        最近更新 更多