Search code examples
react-nativecookieswebview

React-native get cookies from WebView


I have a webview, and I am logging into a website in it, and I want the auth cookies to persist the login, so I can just set the cookie for the user every time, so they don't need to log in every time.

Is this possible? How can I get the cookie from the webview?

Here is my webview:

<View style={styles.container}>
    <WebView
      source={{ uri: "anywebsite.com" }}
      onLoadStart={this.loadingStarted}
      onLoad={this.loadingEnded}
    />
  </View>

Solution

  • You can use react-native-cookies for handling cookies in RN.

    Note that there is also an attribute on WebView called thirdPartyCookiesEnabled. You should try it out and see if it works for your case, cause manually setting and getting the cookies in the WebView takes some time to set up even with a library like react-native-cookies.