繁体   English   中英

Vuejs / Vue-auth令牌已从IE中的localStorage中删除,Edge在Chrome和FF中有效

[英]Vuejs / Vue-auth Token is removed from localStorage in IE and Edge works in Chrome and FF

使用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中完全一样。

除了使用refesh token选项外,我没有对其插件做任何自定义操作,因为我们不使用它们。

我知道这可能是在这里寻找修复程序的远景,但是我已经尝试使用github问题( https://github.com/websanova/vue-auth/issues/309 )徒劳无功。

我...讨厌... IE ...

如果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开发人员,所以这很有启发性。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM