Meteor.js登录事件 [英] Meteor.js on login event

查看:79
本文介绍了Meteor.js登录事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我对meteor框架和JavaScript一般都很陌生,但我正在研究一个使用框架的小项目来尝试让自己从头开始。基本上我在微博客网站上工作。

So I'm rather new to the meteor framework and JavaScript in general, but I'm working on a little project using the framework to try and bring myself up to scratch. Basically I'm working on a micro blogging site.

目前,用户可以通过多种服务,fb,google等登录。我通过以下方式检索他们的头像将服务ID插入到所需的URL中,所有这些都可以正常工作。但我希望用户能够在登录后立即看到自己的头像,这意味着我需要在登录成功后立即运行一些JavaScript。此时我无法在onLogin样式事件中找到任何内容。并且在用户登录时将一个把手模板拼凑在一起以运行代码。但是这段代码似乎只运行一次,如果用户退出然后又回来,他们就不再看到他们的头像了。

At the moment users are able to log in through several services, fb, google etc. And I retrieve their avatars via the service id inserted into the needed url, all this works fine. But I want the user to be able to see their own avatar as soon as they log in which means I need to run some JavaScript right after login is successful. At this point in time I cant find anything on an onLogin style event. And have hacked together a handlebars template to run the code when a user logs in. However this code appears to only run once and if a user logs out and then back in they don't see their avatar anymore.

有没有人知道我可以用来做这个事件?

Does anyone know of an event I can use to do this?

这是我的hacky模板

here is my hacky template

{{#if currentUser}}
    {{> userInput}}
{{/if}}

这里是它调用的js

$('#inputAvatar').css('background-image', 'url('+avatarUrl+')');

我真的很感激帮助,我确信它很简单,我忽略了但是我似乎无法搞清楚!

I would really appreciate the help, I'm sure it's something simple that I've overlooked but I cant seem to figure it out!

谢谢,彼得。

推荐答案

我不知道是否你这样做的方式是最合适的,但是在客户端亲自执行以下操作来检测用户是否已登录:

I don't know if the way you're doing it is the most appropriate but personally do the following on the client side to detect if a user logged in:

Tracker.autorun(function(){
  if(Meteor.userId()){
    //do your stuff
  }
});

这篇关于Meteor.js登录事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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