本文介绍了在窗口/选项卡关闭时注销流星用户,但不在页面刷新时注销.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 window.onbeforeunload 在浏览器选项卡关闭时注销流星用户.它在选项卡关闭时工作正常,但我的用户在我不想要的页面刷新时注销.有没有办法解决这个问题.我希望用户不要在页面刷新时注销.我是 Meteor 的新手.任何帮助将不胜感激.我为此使用的代码是

I have used window.onbeforeunload to logout a meteor user on browser tab close. It works fine with tab close but my user gets log out on page refresh which I do not want. Is there any solution to this problem. I want user to not logout on page refresh. I am new in Meteor. Any help would be highly appreciated. The code I have used for this is

window.onbeforeunload = function() {
         Meteor.logout();
      }

推荐答案

我对meteor 也有点陌生,经过多次尝试,我找到了这个解决方案:

I'm kinda new to meteor too and after many tries I found this solution :

  if (sessionStorage.getItem('session') === null) {
    Meteor.logout();
  }
  window.onload=function(){
    sessionStorage.setItem('session','on');
  };

此代码在我的 Meteor.startup 函数中.像这样,只有当它是一个新会话而不是页面刷新时,用户才会在流星启动时注销.

This code is in my Meteor.startup function. Like that, user will be logged out on meteor startup only if it is a new session and not a refresh of the page.

这篇关于在窗口/选项卡关闭时注销流星用户,但不在页面刷新时注销.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-08 12:16