【问题标题】:Vuejs / Vue-auth Token is removed from localStorage in IE and Edge works in Chrome and FFVuejs / Vue-auth 令牌已从 IE 中的 localStorage 中删除,Edge 可在 Chrome 和 FF 中使用
【发布时间】:2018-07-26 09:51:27
【问题描述】:

使用 VUE 2 和插件 vue-auth (https://github.com/websanova)。无论出于何种原因,在 IE 和 Edge 中,身份验证令牌都会在页面刷新时从 localStorage 中删除,但在 Chrome 中,FF 一切正常,并且不会删除令牌。

我一直在使用 chrome 进行开发,并且即将推出产品。正在其他浏览器中进行测试,然后在开发阶段接近尾声时遇到了这个问题。使用他们的文档,我基本上是在没有任何实际更改的情况下进行设置。

Vue.use(require('@websanova/vue-auth'), {
  auth: require('@websanova/vue-auth/drivers/auth/bearer.js'),
  http: require('@websanova/vue-auth/drivers/http/axios.1.x.js'),
  router: require('@websanova/vue-auth/drivers/router/vue-router.2.x.js'),
  refreshData: {enabled: false},
});

Vue.auth.login({
        method: 'post',
        data: {email: payload.email, password: payload.password, rememberMe: true},
      }).catch(error => {
        console.log('error happened');
        console.log(error);
      })

打开 IE,进入页面,登录,查看 localStorage default_auth_token 是否存在。 按 F5 用户被注销。 Vuew localStorage 和 default_auth_token 不见了。

在 IE 中完全一样。

除了禁用刷新令牌选项之外,我没有对他们的插件进行任何自定义操作,因为我们不使用它们。

我知道在这里寻找修复可能是一个漫长的过程,但我已经尝试使用 github 问题 (https://github.com/websanova/vue-auth/issues/309) 无济于事。

【问题讨论】:

    标签: javascript vuejs2 jwt


    【解决方案1】:

    我……讨厌……我……

    如果 cookie 的域是 localhost(没有三点域,例如 foo.bar.com),那么 IE 和 Edge 就会让它通过而不会出错。 Cookie 未保存,您不知道为什么。

    function setCookie (name, value, timeOffset) {
      var domain = this.options.cookieDomain();
      var expires = (new Date((new Date()).getTime() + timeOffset)).toUTCString();
      if (domain === 'localhost'){
        document.cookie = name + '=' + value + '; Expires=' + expires + ';Path=/;';
      } else {
        document.cookie = name + '=' + value + '; Expires=' + expires + ';Path=/; Domain=' + domain + ';';
      }  
    }
    

    这花了我一整天的时间来跟踪这个插件,但现在我真正理解了它是如何工作的。我通常是后端 python 开发人员,所以这很有启发性。

    【讨论】:

      猜你喜欢
      • 2020-05-17
      • 1970-01-01
      • 2019-11-19
      • 2018-08-21
      • 1970-01-01
      • 1970-01-01
      • 2021-08-18
      • 2012-10-13
      • 1970-01-01
      相关资源
      最近更新 更多