如何在 Meteor 注销时删除会话变量? [英] How can I delete session variables on logout in Meteor?

查看:13
本文介绍了如何在 Meteor 注销时删除会话变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为一个用户设置了会话变量,我用来跟踪和服务小的更改,当用户注销和新用户登录而不关闭浏览器时,会话变量仍然处于活动状态.

I have set session variables for a user that I use to track and server small changes and when a user logs out and a new user Signs in without closing the browser the session variables are still active.

示例 Session.set("variable", variable)Session.get("变量")

Example Session.set("variable", variable) Session.get("variable")

我想我正在寻找的是如何在用户注销时强制页面重新加载.

I guess what I'm looking for is how to force page reload on user logout.

推荐答案

我有一个加载微调器的简单注销模板:

I have a simple logout template that loads a spinner:

<template name="logout">
  {{> spinner}} <!-- using sacha:spin package ->
</template>

然后是一个执行实际注销以及所有清理工作的助手.

Then a helper that does the actual logging out as well as all the cleanup.

Template.logout.rendered = function(){
  Meteor.logout(function(err){
    if ( err ){
      Alerts.add('Error logging out: '+err); // using mrt:bootstrap-alerts
    } else {
      // your cleanup code here
      Object.keys(Session.keys).forEach(function(key){
        Session.set(key, undefined);
      });
      Session.keys = {}; // remove session keys
      Router.go('/');  // redirect to the home page or elsewhere using iron:router
    }
  });
}

另见how-do-i-delete-or-remove-session-variables

这篇关于如何在 Meteor 注销时删除会话变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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