简体   繁体   English

无法在移动设备上设置本地存储,做出反应

[英]Can't set local storage on mobile, react

I'm trying to save a JSON Web Token in local storage for authentication purposes. 我正在尝试将JSON Web令牌保存在本地存储中以进行身份​​验证。 When a user logs in I call the following method. 当用户登录时,我调用以下方法。

  static authenticateUser(token) {
    try {
      window.localStorage.setItem('token', token);
    } catch (error) {
      alert(error);
    }
  }

This works well on desktop but doesn't work at all on mobile. 这在台式机上效果很好,但在移动设备上根本不起作用。 Safari throws a QuotaExceededError and Chrome fails silently. Safari抛出QuotaExceededError ,Chrome静默失败。 Is localStorage not a viable solution for mobile? localStorage是否不是适用于移动设备的可行解决方案? Should I use cookies instead? 我应该改用Cookie吗?

Safari throws QuotaExceededError in Private Mode. Safari在私有模式下引发QuotaExceededError Just check if you are using provide mode. 只要检查您是否正在使用提供模式即可。 Also, try to use sessionStorage instead of localStorage unless you need to store information independent of user' session. 另外,除非需要独立于用户会话存储信息,否则请尝试使用sessionStorage而不是localStorage

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

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