Meteor.loginWithPassword回调未在用户帐户文档中提供自定义对象 [英] Meteor.loginWithPassword callback doesn't provide custom object in User accounts doc

查看:162
本文介绍了Meteor.loginWithPassword回调未在用户帐户文档中提供自定义对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

流星loginWithPassword()函数没有向我提供对象systemData,我在注册过程中将其添加到用户doc(而不是个人资料obj)中.问题是,如果我在登录后查看控制台,就会可以看到该对象systemData(这可能不是发布问题),但是在我需要的loginWithPassword()函数的回调中却没有它们(将用户动态重定向到正确的页面).是否有办法获取此对象,而没有计时器等任何丑陋的东西?

Meteors loginWithPassword() function doesn't provide me the object systemData, which I adding to user doc (not to profile obj) during registration. The thing is, that if I look into console after logging in, I can see that object systemData (that means probably it's not publish issue), but not in callback of loginWithPassword() function, where I need them (to dynamically redirect user to proper page). Is there way to get this object, without any ugly things like timers?

Meteor.loginWithPassword(email, password, function(errorObject) {
if (errorObject) {
 ...
} else {

// returns true
if (Meteor.userId()) {
    // returns false
    if (Meteor.user().systemData) {
    ...
    }
    // user doc without systemData object
    console.log(JSON.stringify(Meteor.user());
}

}

我在创建用户时添加了对象systemData:

I've adding object systemData on creating user:

Accounts.onCreateUser(function(options, user) {

if (options.profile) {
user.profile = options.profile;
}
...
user.systemData = systemDataRegularUser;
return user;
});

推荐答案

我没有找到解决此问题的确切方法,但是找到了简单的解决方法. 要在用户登录后立即执行某些操作(例如,将用户动态重定向到正确的页面),您可以使用Iron路由器挂接到主页.(如果使用的话):

I didn't find exact way how to solve this, but found easy workaround. To make some action right after user logged in (eg. dynamically redirect user to proper page), you can hook on your home page with Iron router.(If you using it.) :

this.route('UsersListingHome', {
  path: '/',
  template: 'UsersListing',
  data: function() { ... },
  before: function() {    
    if (isCurrentUserAdmin() && Session.get('adminJustLogged') !== 'loggedIn') {
      Router.go('/page-to-redirect');
      Session.set('adminJustLogged','loggedIn');    
    }
  }
});

单击课程if (isCurrentUserAdmin()) { Session.set('adminJustLogged', null); }

我还考虑过在方法回调中调用Meteor.call('someMethod')来获取userData对象,但是现在我很满意.

I've further thought about calling Meteor.call('someMethod') to fetch userData object in Method callback, but now I'm satisfied.

PS:我知道不建议使用大量会话变量或其他反应性数据源来加快我的应用程序的运行速度,但我相信这不是悲剧:) PS2:不管怎么说,谢谢您的回答.

PS: I know that it's not recommended to have plenty session variables or other reactive data source for speeding-up my app, but I believe, that one is not tragedy :) PS2: Anyway, thanks for your answers.

这篇关于Meteor.loginWithPassword回调未在用户帐户文档中提供自定义对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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