react-native-cookie-handler
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

react-native-cookie-handler

A React Native library for managing cookies on both iOS and Android platforms, including HTTP only cookies.

Installation

npm install react-native-cookie-handler

or

yarn add react-native-cookie-handler

Additional Setup for iOS

If 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

Supported platforms

Platforms
IOS
Android

Usage

Importing the Library

import * as CookieHandler from 'react-native-cookie-handler';

API

get(url: string, useWebkit?: boolean): Promise<{ [key: string]: string }>

Get cookies for a specific URL.

const cookies = await CookieHandler.get('https://example.com', true);
console.log(cookies);

set(url: string, cookie: Cookie, useWebKit?: boolean): Promise<boolean>

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);

clearAll(useWebKit?: boolean): Promise<void>

Clear all cookies.

await CookieHandler.clearAll(true);

clearCookiesForURL(url: string, useWebkit?: boolean): Promise<void>

Clear cookies for a specific URL.

await CookieHandler.clearCookiesForURL('https://example.com', true);

clearSelectedCookiesForURL(url: string, cookieNames: string[], useWebkit?: boolean): Promise<void>

Clear selected cookies for a specific URL.

await CookieHandler.clearSelectedCookiesForURL('https://example.com', ['myCookie'], true);

Contributing

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.

License

MIT

Package Sidebar

Install

npm i react-native-cookie-handler

Weekly Downloads

3

Version

1.0.1

License

MIT

Unpacked Size

32.5 kB

Total Files

20

Last publish

Collaborators

  • orcunorcun