简体   繁体   English

Meteor.logout()之后,其他浏览器窗口不会返回用户登录页面

[英]Other browser windows don't go back to user login page after Meteor.logout()

I have written a meteor application with user login. 我已经用用户登录编写了一个流星应用程序。 After a user logs out, the application redirects to the user login page. 用户注销后,应用程序将重定向到用户登录页面。 However, when they are multiple tabs in the browser (or multiple browser windows) where the application is active (and the user is logged in), only the active tab or browser window goes back to the user login page. 但是,当它们是应用程序处于活动状态(并且用户已登录)的浏览器(或多个浏览器窗口)中的多个选项卡时,只有活动的选项卡或浏览器窗口会返回到用户登录页面。 In the other window it seems the user is still logged in. However, when the user does some further work in the other window, nothing is synced with the db on the server anymore. 在另一个窗口中,似乎用户仍在登录。但是,当用户在另一个窗口中进行进一步的工作时,服务器上的数据库不再同步。 I thought Meteor.logout() is reactive, so how is it possible that the other browser tabs or windows don't refresh? 我以为Meteor.logout()是反应性的,那么其他浏览器选项卡或窗口怎么可能不刷新?

I have the folowwing in my router?js file: 我的router?js文件中包含以下文件:

var filters = {
 isLoggedIn : function(pause) {
  if(!Meteor.user()){
   this.render('login');
  } else {
   this.next();
  }
 }

....

}

Router.onBeforeAction(filters.isLoggedIn);

After pushing the logout button the following js code is executed 按下注销按钮后,将执行以下js代码

Meteor.logout();

Thanks for the help. 谢谢您的帮助。

Try this: 尝试这个:

Meteor.logoutOtherClients

Meteor.logoutOtherClients should log out all sessions. Meteor.logoutOtherClients应该注销所有会话。 It is designed for situations where the user is logged in on multiple devices and wants to log out on all of them simultaneously. 它设计用于以下情况:用户在多个设备上登录,并希望同时注销所有设备。

In my app I didn't want to use a global redirect on logout, but on some templates to redirect to another template if logout happens. 在我的应用程序中,我不想在注销时使用全局重定向,但是在某些模板上,如果注销会重定向到另一个模板。

Following Autumn Leonard's comment, I made this work by having the particular template reactive by creating a template.mytemplate.onCreated function and inside there put an autorun function checking Meteor.user() and doing the redirect. 按照秋天伦纳德的评论,我通过创建template.mytemplate.onCreated函数使特定的模板具有响应性来完成这项工作,并在其中放置了一个自动运行的函数来检查Meteor.user()并进行重定向。

I hope this approach helps others :) 我希望这种方法可以帮助其他人:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM