【问题标题】:React-native, clear webview cookie?React-native,清晰的 webview cookie?
【发布时间】:2017-10-15 15:58:50
【问题描述】:

可以清除 react-native webview cookie 吗?当我替换到其他视图并再次返回并安装 webview 时,看起来 cookie 仍然存在于 webview 中..

问候

【问题讨论】:

  • 有一些模块他们创建cookie并清除它们。 github.com/joeferraro/react-native-cookies
  • 您找到解决方法了吗?我正在使用库来处理它,但谷歌似乎总是在 Android 上登录,尽管我可以在 iOS 上清除它们以注销用户。
  • 所以,最后我在服务器端创建了一个方法(例如注销),强制用户自动登录和重新创建 cookie。没有这个,清除组件后,webview 仍然可以访问之前的用户数据。

标签: reactjs react-native cookies webview


【解决方案1】:

您可以使用react-native-cookies 来管理您的应用cookies。

import CookieManager from 'react-native-cookies';
// clear cookies on webview will mount!
CookieManager.clearAll()
  .then((res) => {
    console.log('CookieManager.clearAll =>', res);
  });

【讨论】:

    【解决方案2】:

    你可以使用 react-native 自带的 AsyncStorage

    import { AsyncStorage } from 'react-native'
    AsyncStorage.setItem('token', user.token)
    AsyncStorage.removeItem('token')
    AsyncStorage.getItem('token', (ignore, result) => {})
    

    请注意 getItem 是基于承诺的功能。

    然后在组件加载检查时创建一个操作/函数,根据上述内容检查用户是否具有对其的授权!

    【讨论】:

      猜你喜欢
      • 2018-02-05
      • 1970-01-01
      • 2021-11-26
      • 2022-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-22
      • 1970-01-01
      相关资源
      最近更新 更多