A React Native library for managing cookies on both iOS and Android platforms, including HTTP only cookies.
npm install react-native-cookie-handleror
yarn add react-native-cookie-handlerIf you're using this library in an iOS project, make sure to navigate to the ios directory and run pod install to install the necessary CocoaPods dependencies:
cd ios
pod install| Platforms | |
|---|---|
| IOS | ✓ |
| Android | ✓ |
import * as CookieHandler from 'react-native-cookie-handler';Get cookies for a specific URL.
const cookies = await CookieHandler.get('https://example.com', true);
console.log(cookies);Set a cookie for a specific URL.
const cookie = {
name: 'myCookie',
value: 'myValue',
domain: 'example.com',
path: '/',
expires: new Date(Date.now() + 86400 * 1000).toUTCString(), // 1 day from now
};
await CookieHandler.set('https://example.com', cookie, true);Clear all cookies.
await CookieHandler.clearAll(true);Clear cookies for a specific URL.
await CookieHandler.clearCookiesForURL('https://example.com', true);Clear selected cookies for a specific URL.
await CookieHandler.clearSelectedCookiesForURL('https://example.com', ['myCookie'], true);Contributions are welcome! Please check out the issues page first to see if your issue has already been reported. If you'd like to contribute, please fork the repository and use a feature branch. Pull requests are warmly welcome.
MIT