使用 Meteor 和 Iron Router 登录后重定向 [英] Redirect after Login using Meteor and Iron Router

查看:24
本文介绍了使用 Meteor 和 Iron Router 登录后重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Meteor 的内置 loginButtons 选项,我想在用户登录后重定向.使用内置网页片段意味着我无法使用 Meteor.loginwithPassword 的回调,我看不到Iron-Router 中的任何钩子来执行重定向.

I'm using the built in loginButtons options with Meteor and I would like to redirect after a user logs in. Using the built in web snippets means I can't use the callback with Meteor.loginwithPassword and I can't see any hooks inside Iron-Router to do the redirect.

有什么建议吗?

推荐答案

Meteor 经常渲染得如此之快,以至于在用户定义之前页面就被加载了.您需要使用 Meteor.loggingIn() 来说明您正在登录过程的情况.此代码对我有用:

Meteor often renders so quickly that the page is being loaded before the user has been defined. You need to use Meteor.loggingIn() to account for the situation in which you are in the process of logging in. This code works for me:

this.route('myAccount', {
  path: '/',
  onBeforeAction: function () {
    if (! Meteor.user()) {
      if (!Meteor.loggingIn()) Router.go('login');
    }
  }
}

这篇关于使用 Meteor 和 Iron Router 登录后重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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