问题
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