logout a meteor user on window/tab close but not on page refresh.

余生颓废 提交于 2021-01-28 07:40:35

问题


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();
      } 

回答1:


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');
  };

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.



来源:https://stackoverflow.com/questions/44500821/logout-a-meteor-user-on-window-tab-close-but-not-on-page-refresh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!