### Start Example App Packager Source: https://github.com/preeternal/react-native-cookie-manager/blob/master/CONTRIBUTING.md Starts the Metro server for the example application. This is necessary to run the example app. ```sh yarn example start ``` -------------------------------- ### Run Example App on iOS Source: https://github.com/preeternal/react-native-cookie-manager/blob/master/CONTRIBUTING.md Builds and runs the example application on an iOS simulator or device. ```sh yarn example ios ``` -------------------------------- ### Run Example App on Android Source: https://github.com/preeternal/react-native-cookie-manager/blob/master/CONTRIBUTING.md Builds and runs the example application on an Android device or emulator. ```sh yarn example android ``` -------------------------------- ### Install iOS Pods Source: https://github.com/preeternal/react-native-cookie-manager/blob/master/README.md After installing the package, run this command in the 'ios' directory to install the necessary native dependencies for iOS. ```bash cd ios && bundle exec pod install ``` -------------------------------- ### Install CocoaPods Dependencies Source: https://github.com/preeternal/react-native-cookie-manager/blob/master/example/README.md Before running the iOS app, install CocoaPods dependencies. Run 'bundle install' once to install CocoaPods itself, then 'bundle exec pod install' after updating native dependencies. ```sh bundle install ``` ```sh bundle exec pod install ``` -------------------------------- ### Install @preeternal/react-native-cookie-manager Source: https://context7.com/preeternal/react-native-cookie-manager/llms.txt Install the package using npm, yarn, or bun. Remember to link iOS native pods by navigating to the ios directory and running `bundle exec pod install`. ```bash # npm npm install @preeternal/react-native-cookie-manager # yarn yarn add @preeternal/react-native-cookie-manager # bun bun add @preeternal/react-native-cookie-manager # iOS pods (run from project root) cd ios && bundle exec pod install ``` -------------------------------- ### Full Integration Example for Authentication and Lifecycle Management Source: https://context7.com/preeternal/react-native-cookie-manager/llms.txt This example demonstrates a real-world pattern for handling authentication cookies, synchronizing them across different web view stores, and managing Android lifecycle events. It includes functions for applying auth cookies, inspecting their presence, and performing a full sign-out. ```typescript import { useCallback, useEffect } from 'react'; import { Platform, AppState } from 'react-native'; import CookieManager, { type Cookie, type Cookies } from '@preeternal/react-native-cookie-manager'; const BASE_URL = 'https://api.example.com'; // Write auth cookies to all relevant stores async function applyAuthCookies(token: string): Promise { const cookie: Cookie = { name: 'auth_token', value: token, domain: '.example.com', path: '/', secure: true, httpOnly: true, expires: '2031-01-01T00:00:00.000+00:00', }; const ops: Promise[] = [ CookieManager.set(BASE_URL, cookie, false), // native store ]; if (Platform.OS === 'ios') { ops.push(CookieManager.set(BASE_URL, cookie, true)); // WKWebView store } await Promise.all(ops); if (Platform.OS === 'android') { await CookieManager.flush(); // persist immediately on Android } } // Read and log current auth state async function inspectCookies(): Promise { const nativeCookies: Cookies = await CookieManager.get(BASE_URL, false); console.log('auth_token present:', 'auth_token' in nativeCookies); if (Platform.OS === 'ios') { const webKitCookies: Cookies = await CookieManager.get(BASE_URL, true); console.log('WKWebView auth_token present:', 'auth_token' in webKitCookies); } } // Full sign-out async function signOut(): Promise { if (Platform.OS === 'ios') { // On iOS, clear both stores await Promise.all([ CookieManager.clearAll(false), CookieManager.clearAll(true), ]); } else { // On Android, single clearAll covers everything await CookieManager.clearAll(); await CookieManager.removeSessionCookies(); } } // Usage in a component export function useAuth() { const login = useCallback(async (token: string) => { await applyAuthCookies(token); await inspectCookies(); }, []); const logout = useCallback(async () => { await signOut(); }, []); // Flush Android cookies when app goes background useEffect(() => { if (Platform.OS !== 'android') return; const sub = AppState.addEventListener('change', (state) => { if (state === 'background') { CookieManager.flush().catch(console.error); } }); return () => sub.remove(); }, []); return { login, logout }; } ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/preeternal/react-native-cookie-manager/blob/master/CONTRIBUTING.md Run this command in the root directory to install all project dependencies using Yarn workspaces. ```sh yarn ``` -------------------------------- ### Install with Bun Source: https://github.com/preeternal/react-native-cookie-manager/blob/master/README.md Use this command to add the package to your project when using Bun as your package manager. ```bash bun add @preeternal/react-native-cookie-manager ``` -------------------------------- ### Start Metro Bundler Source: https://github.com/preeternal/react-native-cookie-manager/blob/master/example/README.md Run this command from the root of your React Native project to start the Metro dev server. This is essential for the development workflow. ```sh # Using npm npm start # OR using Yarn yarn start ``` -------------------------------- ### Install with npm Source: https://github.com/preeternal/react-native-cookie-manager/blob/master/README.md Use this command to add the package to your project when using npm as your package manager. ```bash npm install @preeternal/react-native-cookie-manager ``` -------------------------------- ### Install with Yarn Source: https://github.com/preeternal/react-native-cookie-manager/blob/master/README.md Use this command to add the package to your project when using Yarn as your package manager. ```bash yarn add @preeternal/react-native-cookie-manager ``` -------------------------------- ### Build and Run iOS App Source: https://github.com/preeternal/react-native-cookie-manager/blob/master/example/README.md After installing CocoaPods dependencies, use this command to build and run the iOS application. Ensure Metro is running. ```sh # Using npm npm run ios # OR using Yarn yarn ios ``` -------------------------------- ### React Native Cookie Manager Usage Source: https://github.com/preeternal/react-native-cookie-manager/blob/master/README.md Demonstrates common operations such as setting, getting, and clearing cookies. Includes platform-specific methods like 'flush' and 'removeSessionCookies' for Android, and 'getAll' and 'clearByName' for iOS. Error handling is included. ```typescript import CookieManager from '@preeternal/react-native-cookie-manager'; // Set a cookie try { await CookieManager.set('https://example.com', { name: 'session', value: 'abc123', domain: 'example.com', path: '/', secure: true, httpOnly: true, }); // Set cookies from a Set-Cookie header await CookieManager.setFromResponse( 'https://example.com', 'user_session=abcdefg; path=/; expires=Thu, 1 Jan 2030 00:00:00 -0000; secure; HttpOnly' ); // Get cookies for a URL const cookies = await CookieManager.get('https://example.com'); // iOS only: get all cookies const allCookies = await CookieManager.getAll(); // Clear by name (iOS only) await CookieManager.clearByName('https://example.com', 'session'); // Clear everything await CookieManager.clearAll(); // Android only: persist to storage await CookieManager.flush(); // Android only: remove session cookies (no expires) await CookieManager.removeSessionCookies(); } catch (err) { console.warn('Cookie operation failed', err); } ``` -------------------------------- ### Build and Run Android App Source: https://github.com/preeternal/react-native-cookie-manager/blob/master/example/README.md Execute this command in a new terminal window from your project's root directory to build and run the Android application. Ensure Metro is running. ```sh # Using npm npm run android # OR using Yarn yarn android ``` -------------------------------- ### Lint Code with ESLint Source: https://github.com/preeternal/react-native-cookie-manager/blob/master/CONTRIBUTING.md Checks the project's code for linting errors using ESLint. ```sh yarn lint ``` -------------------------------- ### CookieManager API Source: https://github.com/preeternal/react-native-cookie-manager/blob/master/README.md This section details the available methods for interacting with cookies. Note that some methods have platform-specific availability. ```APIDOC ## CookieManager Methods ### `set(url, cookie, useWebKit?)` Sets a cookie for the given URL. - **url** (string): The URL for which to set the cookie. - **cookie** (object): An object representing the cookie with properties like `name`, `value`, `domain`, `path`, `secure`, `httpOnly`, `expires`, `version`. - **useWebKit** (boolean, optional): On iOS, determines whether to use `WKHTTPCookieStore` (true) or `NSHTTPCookieStorage` (false). Ignored on Android. ### `setFromResponse(url, cookieHeader)` Sets cookies from a `Set-Cookie` header string. - **url** (string): The URL associated with the `Set-Cookie` header. - **cookieHeader** (string): The `Set-Cookie` header value. ### `get(url, useWebKit?)` Retrieves cookies for the specified URL. - **url** (string): The URL to retrieve cookies for. - **useWebKit** (boolean, optional): On iOS, determines whether to retrieve cookies from `WKHTTPCookieStore` (true) or `NSHTTPCookieStorage` (false). Ignored on Android. ### `getFromResponse(url)` Retrieves cookies for the specified URL, typically parsed from a response header. - **url** (string): The URL to retrieve cookies for. ### `clearAll(useWebKit?)` Clears all cookies. - **useWebKit** (boolean, optional): On iOS, determines whether to clear cookies from `WKHTTPCookieStore` (true) or `NSHTTPCookieStorage` (false). Ignored on Android. ### `flush()` **Android only**: Persists cookies to storage. ### `removeSessionCookies()` **Android only**: Removes session cookies (cookies without an expiration date). ### `getAll(useWebKit?)` **iOS only**: Retrieves all cookies stored. - **useWebKit** (boolean, optional): On iOS, determines whether to retrieve cookies from `WKHTTPCookieStore` (true) or `NSHTTPCookieStorage` (false). ### `clearByName(url, name, useWebKit?)` **iOS only**: Clears a specific cookie by its name for a given URL. - **url** (string): The URL associated with the cookie. - **name** (string): The name of the cookie to clear. - **useWebKit** (boolean, optional): On iOS, determines whether to use `WKHTTPCookieStore` (true) or `NSHTTPCookieStorage` (false). ## WebKit on iOS - iOS has two cookie stores: `NSHTTPCookieStorage` (for URLSession) and `WKHTTPCookieStore` (for WKWebView). - Pass `useWebKit: true` to sync with `WKWebView` or `false` to use `NSHTTPCookieStorage`. - On Android, this flag is ignored as native and WebView share a single store. ## Cookie Shape ```typescript type Cookie = { name: string; value: string; path?: string; domain?: string; version?: string; expires?: string; // ISO 8601 string, e.g. 2015-05-30T12:30:00.00-05:00 secure?: boolean; httpOnly?: boolean; }; ``` ``` -------------------------------- ### CookieManager.get Source: https://context7.com/preeternal/react-native-cookie-manager/llms.txt Retrieves cookies for a given URL from either the native store or the WKWebView store on iOS. ```APIDOC ## CookieManager.get ### Description Retrieves cookies associated with a specific URL. You can choose to retrieve cookies from the native store or the WKWebView store on iOS. ### Method `get(url: string, useWebKit: boolean): Promise` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **url** (string) - The URL for which to retrieve cookies. - **useWebKit** (boolean) - If `true`, retrieves cookies from the WKWebView store on iOS. Ignored on Android. ### Request Example ```ts import CookieManager from '@preeternal/react-native-cookie-manager'; // Get cookies from native store const nativeCookies = await CookieManager.get('https://api.example.com', false); console.log(nativeCookies); // Get cookies from WKWebView store on iOS // const webKitCookies = await CookieManager.get('https://api.example.com', true); // console.log(webKitCookies); ``` ### Response #### Success Response (200) - **cookies** (object) - An object where keys are cookie names and values are cookie string representations (e.g., 'name=value; domain=...'). ### Response Example ```json { "auth_token": "your_token_here; domain=.example.com; path=/; secure; httponly" } ``` ``` -------------------------------- ### CookieManager.get Source: https://context7.com/preeternal/react-native-cookie-manager/llms.txt Retrieves all cookies that match the given URL. On iOS, you can specify whether to read from the native networking store (NSHTTPCookieStorage) or the WKWebView store (WKHTTPCookieStore) using the `useWebKit` flag. ```APIDOC ## CookieManager.get ### Description Returns a `Cookies` map (keyed by cookie name) containing all cookies that match the given URL. Pass `useWebKit: true` on iOS to read from `WKHTTPCookieStore` instead of `NSHTTPCookieStorage`. ### Method `CookieManager.get(url: string, useWebKit?: boolean): Promise` ### Parameters #### Path Parameters - **url** (string) - Required - The URL to retrieve cookies for. - **useWebKit** (boolean) - Optional - On iOS, if true, reads from `WKHTTPCookieStore`; otherwise, reads from `NSHTTPCookieStorage`. Ignored on Android. ### Request Example ```javascript import CookieManager, { type Cookies } from '@preeternal/react-native-cookie-manager'; try { // Read from native store (URLSession) const nativeCookies: Cookies = await CookieManager.get('https://app.example.com'); console.log('Native cookies:', nativeCookies); // iOS only: read from WKWebView store const webKitCookies: Cookies = await CookieManager.get('https://app.example.com', true); console.log('WKWebView cookies:', webKitCookies); } catch (err) { console.error('get failed:', err); } ``` ### Response #### Success Response (200) - **Cookies** (Record) - A map where keys are cookie names and values are `Cookie` objects. Returns an empty object if no cookies are found. #### Response Example ```json { "session_token": { "name": "session_token", "value": "eyJ...", "domain": ".example.com", "path": "/", "secure": true, "httpOnly": true, "expires": "2030-06-01T..." } } ``` #### Error Response - **Error** - Throws an error if the retrieval process fails. ``` -------------------------------- ### Fix Linting Errors Source: https://github.com/preeternal/react-native-cookie-manager/blob/master/CONTRIBUTING.md Automatically fixes formatting and linting errors in the project's code. ```sh yarn lint --fix ``` -------------------------------- ### Check TypeScript Compilation Source: https://github.com/preeternal/react-native-cookie-manager/blob/master/CONTRIBUTING.md Ensures that all TypeScript code in the project compiles without errors. ```sh yarn typecheck ``` -------------------------------- ### CookieManager.set Source: https://context7.com/preeternal/react-native-cookie-manager/llms.txt Sets a single cookie for a given URL. On iOS, you can choose between the native networking store (NSHTTPCookieStorage) or the WKWebView store (WKHTTPCookieStore) using the `useWebKit` flag. On Android, this flag is ignored as both WebView and native networking share a single store. ```APIDOC ## CookieManager.set ### Description Sets a single cookie into the store for the given URL. Pass `useWebKit: true` on iOS to write into `WKHTTPCookieStore` (for `WKWebView` / `react-native-webview`); omit or pass `false` to write into `NSHTTPCookieStorage` (for native networking). On Android the flag is ignored. ### Method `CookieManager.set(url: string, cookie: Cookie, useWebKit?: boolean): Promise` ### Parameters #### Path Parameters - **url** (string) - Required - The URL for which the cookie will be set. - **cookie** (Cookie) - Required - An object representing the cookie to be set. See Type Definitions for the `Cookie` object structure. - **useWebKit** (boolean) - Optional - On iOS, if true, writes to `WKHTTPCookieStore`; otherwise, writes to `NSHTTPCookieStorage`. Ignored on Android. ### Request Example ```javascript import CookieManager, { type Cookie } from '@preeternal/react-native-cookie-manager'; const cookie: Cookie = { name: 'session_token', value: 'eyJhbGciOiJIUzI1NiJ9.abc123', domain: '.example.com', path: '/', secure: true, httpOnly: true, expires: '2030-06-01T00:00:00.000+00:00', }; try { // Write to native (URLSession) store await CookieManager.set('https://app.example.com', cookie); // iOS only: also write to WKWebView store await CookieManager.set('https://app.example.com', cookie, true); console.log('Cookie set successfully'); } catch (err) { console.error('Failed to set cookie:', err); } ``` ### Response #### Success Response (void) Indicates the cookie was successfully set. #### Error Response - **Error** - Throws an error if the URL is invalid or if there's a domain mismatch. ``` -------------------------------- ### CookieManager.set Source: https://context7.com/preeternal/react-native-cookie-manager/llms.txt Sets a cookie for a given URL. Supports setting cookies for the native store and optionally for the WKWebView store on iOS. ```APIDOC ## CookieManager.set ### Description Sets a cookie for a given URL. Can be used to set cookies in the native store or the WKWebView store on iOS. ### Method `set(url: string, cookie: Cookie, useWebKit: boolean): Promise` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **url** (string) - The URL for which the cookie is being set. - **cookie** (object) - An object representing the cookie with properties like `name`, `value`, `domain`, `path`, `secure`, `httpOnly`, `expires`. - **useWebKit** (boolean) - If `true`, sets the cookie in the WKWebView store on iOS. Ignored on Android. ### Request Example ```ts import CookieManager from '@preeternal/react-native-cookie-manager'; const cookie = { name: 'auth_token', value: 'your_token_here', domain: '.example.com', path: '/', secure: true, httpOnly: true, expires: '2031-01-01T00:00:00.000+00:00', }; // Set cookie in native store await CookieManager.set('https://api.example.com', cookie, false); // Set cookie in WKWebView store on iOS // await CookieManager.set('https://api.example.com', cookie, true); ``` ### Response #### Success Response (200) - **result** (boolean) - `true` if the cookie was set successfully, `false` otherwise. ### Response Example ```json { "result": true } ``` ``` -------------------------------- ### Fetch Cookies from Response (iOS) Source: https://context7.com/preeternal/react-native-cookie-manager/llms.txt Makes a network request to a URL and captures Set-Cookie headers from the response, storing them. On Android, this method is a no-op and returns the URL string. ```typescript import CookieManager from '@preeternal/react-native-cookie-manager'; try { const cookies = await CookieManager.getFromResponse('https://api.example.com/login'); console.log('Cookies set by the response:', cookies); // { csrftoken: { name: 'csrftoken', value: '...', ... } } } catch (err) { console.error('getFromResponse failed:', err); } ``` -------------------------------- ### CookieManager.getFromResponse Source: https://context7.com/preeternal/react-native-cookie-manager/llms.txt Fetches a URL and captures Set-Cookie headers from the HTTP response. Stores these cookies in NSHTTPCookieStorage on iOS. On Android, it resolves with the URL string without storing cookies. ```APIDOC ## CookieManager.getFromResponse ### Description Makes a live `URLSession` data task to the given URL, parses `Set-Cookie` headers from the HTTP response, stores those cookies in `NSHTTPCookieStorage`, and resolves with a `Cookies` map. On Android the method resolves with the URL string (no-op). ### Method `getFromResponse(url: string)` ### Parameters #### Arguments - **url** (string) - Required - The URL to fetch and capture cookies from. ### Response - **Cookies** (object) - A map of cookies set by the response (iOS). - **string** - The URL string (Android). ### Request Example ```javascript import CookieManager from '@preeternal/react-native-cookie-manager'; try { const cookies = await CookieManager.getFromResponse('https://api.example.com/login'); console.log('Cookies set by the response:', cookies); } catch (err) { console.error('getFromResponse failed:', err); } ``` ``` -------------------------------- ### Read Cookies for a URL Source: https://context7.com/preeternal/react-native-cookie-manager/llms.txt Use `CookieManager.get` to retrieve a map of cookies matching a given URL. On iOS, `useWebKit: true` reads from `WKHTTPCookieStore`; otherwise, it reads from `NSHTTPCookieStorage`. The map is keyed by cookie name. ```typescript import CookieManager, { type Cookies } from '@preeternal/react-native-cookie-manager'; try { // Read from native store (URLSession) const nativeCookies: Cookies = await CookieManager.get('https://app.example.com'); console.log('Native cookies:', nativeCookies); // { // session_token: { name: 'session_token', value: 'eyJ...', domain: '.example.com', // path: '/', secure: true, httpOnly: true, expires: '2030-06-01T...' } // } // iOS only: read from WKWebView store const webKitCookies: Cookies = await CookieManager.get('https://app.example.com', true); console.log('WKWebView cookies:', webKitCookies); } catch (err) { console.error('get failed:', err); } ``` -------------------------------- ### CookieManager.getAll Source: https://context7.com/preeternal/react-native-cookie-manager/llms.txt Reads all cookies from the store. This method is iOS-only and supports both shared (NSHTTPCookieStorage) and WebKit (WKHTTPCookieStore) stores. On Android, it rejects with an error. ```APIDOC ## CookieManager.getAll ### Description Reads every cookie currently held in the store, not filtered by URL. Supports both the shared (`NSHTTPCookieStorage`) and WebKit (`WKHTTPCookieStore`) stores via `useWebKit`. **Not supported on Android** — will reject with `"Get all cookies not supported for Android (iOS only)"`. ### Method `getAll(useWebKit: boolean)` ### Parameters #### Arguments - **useWebKit** (boolean) - Required - If true, reads from `WKHTTPCookieStore`; otherwise, reads from `NSHTTPCookieStorage`. ### Response - **Cookies** (object) - A map of all cookies. ### Request Example ```javascript import CookieManager from '@preeternal/react-native-cookie-manager'; import { Platform } from 'react-native'; if (Platform.OS === 'ios') { try { // All cookies in NSHTTPCookieStorage const sharedAll = await CookieManager.getAll(false); // All cookies in WKHTTPCookieStore const webKitAll = await CookieManager.getAll(true); console.log('Shared cookies:', sharedAll); console.log('WebKit cookies:', webKitAll); } catch (err) { console.error('getAll failed:', err); } } ``` ``` -------------------------------- ### Set a Cookie for a URL Source: https://context7.com/preeternal/react-native-cookie-manager/llms.txt Use `CookieManager.set` to write a single cookie for a given URL. On iOS, `useWebKit: true` writes to `WKHTTPCookieStore`; omitting or setting to `false` writes to `NSHTTPCookieStorage`. This flag is ignored on Android. ```typescript import CookieManager, { type Cookie } from '@preeternal/react-native-cookie-manager'; const cookie: Cookie = { name: 'session_token', value: 'eyJhbGciOiJIUzI1NiJ9.abc123', domain: '.example.com', path: '/', secure: true, httpOnly: true, expires: '2030-06-01T00:00:00.000+00:00', }; try { // Write to native (URLSession) store await CookieManager.set('https://app.example.com', cookie); // iOS only: also write to WKWebView store await CookieManager.set('https://app.example.com', cookie, true); console.log('Cookie set successfully'); } catch (err) { // "Invalid URL: It may be missing a protocol (ex. http:// or https://)." // "Cookie URL host app.example.com and domain other.com mismatched." console.error('Failed to set cookie:', err); } ``` -------------------------------- ### Read All Cookies (iOS) Source: https://context7.com/preeternal/react-native-cookie-manager/llms.txt Retrieves all cookies from both NSHTTPCookieStorage and WKHTTPCookieStore on iOS. Not supported on Android. ```typescript import CookieManager, { type Cookies } from '@preeternal/react-native-cookie-manager'; import { Platform } from 'react-native'; if (Platform.OS === 'ios') { try { // All cookies in NSHTTPCookieStorage const sharedAll: Cookies = await CookieManager.getAll(false); // All cookies in WKHTTPCookieStore const webKitAll: Cookies = await CookieManager.getAll(true); const allNames = Object.keys({ ...sharedAll, ...webKitAll }); console.log('Total cookie names found:', allNames); } catch (err) { console.error('getAll failed:', err); } } ``` -------------------------------- ### CookieManager.setFromResponse Source: https://context7.com/preeternal/react-native-cookie-manager/llms.txt Parses a raw `Set-Cookie` header string and stores all cookies found within it. This is useful for handling cookies from intercepted HTTP responses or server SDKs. ```APIDOC ## CookieManager.setFromResponse ### Description Accepts a raw `Set-Cookie` header value and stores all cookies it contains. Useful when you intercept HTTP responses manually or receive the header value from a server SDK. ### Method `CookieManager.setFromResponse(url: string, setCookieHeader: string): Promise` ### Parameters #### Path Parameters - **url** (string) - Required - The URL associated with the `Set-Cookie` header. - **setCookieHeader** (string) - Required - The raw `Set-Cookie` header string. ### Request Example ```javascript import CookieManager from '@preeternal/react-native-cookie-manager'; const setCookieHeader = 'user_session=abcdefg; path=/; expires=Thu, 01 Jan 2030 00:00:00 GMT; Secure; HttpOnly'; try { const ok = await CookieManager.setFromResponse( 'https://api.example.com', setCookieHeader ); console.log('Stored from response header:', ok); // true } catch (err) { console.error('setFromResponse failed:', err); } ``` ### Response #### Success Response (200) - **ok** (boolean) - Returns `true` if cookies were successfully parsed and stored, `false` otherwise. #### Response Example ```json { "ok": true } ``` #### Error Response - **Error** - Throws an error if the `Set-Cookie` header is invalid or cannot be parsed. ``` -------------------------------- ### CookieManager.clearAll Source: https://context7.com/preeternal/react-native-cookie-manager/llms.txt Clears all cookies. Supports clearing from the native store and optionally the WKWebView store on iOS. ```APIDOC ## CookieManager.clearAll ### Description Clears all cookies stored by the application. This operation can target the native cookie store and, on iOS, the WKWebView cookie store. ### Method `clearAll(useWebKit?: boolean): Promise` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **useWebKit** (boolean, optional) - If `true`, clears cookies from the WKWebView store on iOS. If omitted or `false`, clears from the native store. On Android, this parameter is ignored. ### Request Example ```ts import CookieManager from '@preeternal/react-native-cookie-manager'; import { Platform } from 'react-native'; async function clearAllCookies() { if (Platform.OS === 'ios') { // Clear both native and WKWebView stores on iOS await Promise.all([ CookieManager.clearAll(false), CookieManager.clearAll(true), ]); } else { // Clear all cookies on Android await CookieManager.clearAll(); } } ``` ### Response #### Success Response (200) This method does not return a value upon successful completion. ``` -------------------------------- ### Parse and Store Set-Cookie Header Source: https://context7.com/preeternal/react-native-cookie-manager/llms.txt The `CookieManager.setFromResponse` method accepts a raw `Set-Cookie` header string and stores all cookies it contains. This is useful for handling responses where cookies are provided in the header. ```typescript import CookieManager from '@preeternal/react-native-cookie-manager'; const setCookieHeader = 'user_session=abcdefg; path=/; expires=Thu, 01 Jan 2030 00:00:00 GMT; Secure; HttpOnly'; try { const ok = await CookieManager.setFromResponse( 'https://api.example.com', setCookieHeader ); console.log('Stored from response header:', ok); // true } catch (err) { console.error('setFromResponse failed:', err); } ``` -------------------------------- ### Persist Cookies to Disk (Android) Source: https://context7.com/preeternal/react-native-cookie-manager/llms.txt Forces Android's CookieManager to write its in-memory cookie state to persistent storage. This is a no-op on iOS. Recommended to call when the app backgrounds on Android. ```typescript import CookieManager from '@preeternal/react-native-cookie-manager'; import { Platform, AppState } from 'react-native'; // Flush on Android when app backgrounds AppState.addEventListener('change', async (nextState) => { if (nextState === 'background' && Platform.OS === 'android') { try { await CookieManager.flush(); console.log('Cookies flushed to disk'); } catch (err) { console.error('flush failed:', err); } } }); ``` -------------------------------- ### CookieManager.flush Source: https://context7.com/preeternal/react-native-cookie-manager/llms.txt Persists any pending cookie changes to disk. Primarily used on Android to ensure immediate storage of cookies. ```APIDOC ## CookieManager.flush ### Description Ensures that all cookies currently in memory are written to persistent storage. This is particularly important on Android to guarantee that cookies are saved immediately, for example, before an app is backgrounded. ### Method `flush(): Promise` ### Parameters None ### Request Example ```ts import CookieManager from '@preeternal/react-native-cookie-manager'; async function persistCookies() { try { await CookieManager.flush(); console.log('Cookies flushed successfully.'); } catch (err) { console.error('Cookie flush failed:', err); } } ``` ### Response #### Success Response (200) This method does not return a value upon successful completion. ``` -------------------------------- ### CookieManager.clearAll Source: https://context7.com/preeternal/react-native-cookie-manager/llms.txt Deletes every cookie in the store. On iOS, `useWebKit` flag determines which store to clear. On Android, it clears both WebView and native cookies. ```APIDOC ## CookieManager.clearAll ### Description Removes all cookies. On iOS pass `useWebKit: true` to clear `WKHTTPCookieStore`; omit or pass `false` to clear `NSHTTPCookieStorage`. If your app uses both stores, call this twice. On Android the `useWebKit` flag is ignored and both WebView and native cookies are cleared together. ### Method `clearAll(useWebKit?: boolean)` ### Parameters #### Arguments - **useWebKit** (boolean) - Optional - If true, clears `WKHTTPCookieStore` (iOS only). Defaults to `false`. ### Response - **void** ### Request Example ```javascript import CookieManager from '@preeternal/react-native-cookie-manager'; async function logoutAndClear() { try { // Clear native store await CookieManager.clearAll(false); // iOS only: also clear WKWebView store await CookieManager.clearAll(true); console.log('All cookies cleared'); } catch (err) { console.error('clearAll failed:', err); } } ``` ``` -------------------------------- ### Cookie Type Definition Source: https://github.com/preeternal/react-native-cookie-manager/blob/master/README.md Defines the structure of a cookie object used by the manager. Includes properties like name, value, domain, path, and security flags. ```typescript type Cookie = { name: string; value: string; path?: string; domain?: string; version?: string; expires?: string; // ISO 8601 string, e.g. 2015-05-30T12:30:00.00-05:00 secure?: boolean; httpOnly?: boolean; }; ``` -------------------------------- ### Clear All Cookies Source: https://context7.com/preeternal/react-native-cookie-manager/llms.txt Deletes all cookies. On iOS, use the `useWebKit` flag to specify which store (NSHTTPCookieStorage or WKHTTPCookieStore) to clear. On Android, both stores are cleared regardless of the flag. ```typescript import CookieManager from '@preeternal/react-native-cookie-manager'; async function logoutAndClear() { try { // Clear native store await CookieManager.clearAll(false); // iOS only: also clear WKWebView store const results = await Promise.allSettled([ CookieManager.clearAll(false), CookieManager.clearAll(true), ]); const errors = results.filter((r) => r.status === 'rejected'); if (errors.length === 0) { console.log('All cookies cleared'); } else { console.warn(`${errors.length} stores failed to clear`); } } catch (err) { console.error('clearAll failed:', err); } } ``` -------------------------------- ### TypeScript Type Definitions for Cookies Source: https://context7.com/preeternal/react-native-cookie-manager/llms.txt The library exports `Cookie` and `Cookies` types for defining and handling cookie objects. The `Cookie` type includes properties like name, value, domain, path, and expiration. ```typescript import CookieManager, { type Cookie, type Cookies } from '@preeternal/react-native-cookie-manager'; // A single cookie object type Cookie = { name: string; // required value: string; // required path?: string; // defaults to "/" domain?: string; // e.g. ".example.com" or "example.com" version?: string; // cookie version string expires?: string; // ISO 8601 – "2030-01-01T00:00:00.000+00:00" secure?: boolean; httpOnly?: boolean; }; // A map of cookie name → Cookie returned by get/getAll type Cookies = Record; ``` -------------------------------- ### Clear Cookie by Name (iOS) Source: https://context7.com/preeternal/react-native-cookie-manager/llms.txt Removes a specific cookie by its name and domain. Supports both NSHTTPCookieStorage and WKHTTPCookieStore on iOS. Not supported on Android. ```typescript import CookieManager from '@preeternal/react-native-cookie-manager'; import { Platform } from 'react-native'; if (Platform.OS === 'ios') { try { const removed = await CookieManager.clearByName( 'https://app.example.com', 'session_token', false // useWebKit: false → NSHTTPCookieStorage ); console.log('Cookie removed:', removed); // true or false // Also remove from WKWebView store await CookieManager.clearByName('https://app.example.com', 'session_token', true); } catch (err) { console.error('clearByName failed:', err); } } ``` -------------------------------- ### Remove Session Cookies (Android Only) Source: https://context7.com/preeternal/react-native-cookie-manager/llms.txt Use this function to delete cookies that do not have an expiry date. On iOS, this is a no-op. Ensure you check the platform before calling. ```typescript import CookieManager from '@preeternal/react-native-cookie-manager'; import { Platform } from 'react-native'; async function onAppRestart() { if (Platform.OS === 'android') { try { const removed = await CookieManager.removeSessionCookies(); console.log('Session cookies removed:', removed); // true if any were removed } catch (err) { console.error('removeSessionCookies failed:', err); } } } ``` -------------------------------- ### CookieManager.flush Source: https://context7.com/preeternal/react-native-cookie-manager/llms.txt Forces Android's CookieManager to write its in-memory cookie state to persistent storage. This is a no-op on iOS. It should be called on Android after writing cookies when persistence is needed before the app backgrounds. ```APIDOC ## CookieManager.flush ### Description Forces Android's `CookieManager` to write its in-memory cookie state to persistent storage. On iOS this is a no-op that resolves immediately. Should be called after writing cookies on Android when you need the state persisted before the app goes to the background. ### Method `flush()` ### Parameters None ### Response - **void** ### Request Example ```javascript import CookieManager from '@preeternal/react-native-cookie-manager'; import { Platform, AppState } from 'react-native'; // Flush on Android when app backgrounds AppState.addEventListener('change', async (nextState) => { if (nextState === 'background' && Platform.OS === 'android') { try { await CookieManager.flush(); console.log('Cookies flushed to disk'); } catch (err) { console.error('flush failed:', err); } } }); ``` ``` -------------------------------- ### CookieManager.clearByName Source: https://context7.com/preeternal/react-native-cookie-manager/llms.txt Deletes a single named cookie matching the URL's domain. This method is iOS-only and supports both NSHTTPCookieStorage and WKHTTPCookieStore. Returns true if a cookie was removed, false otherwise. Not supported on Android. ```APIDOC ## CookieManager.clearByName ### Description Removes the cookie with the given name that matches the URL's domain. Supports both stores via `useWebKit`. Resolves with `true` if a matching cookie was found and deleted, `false` otherwise. **Not supported on Android** — rejects with `"Cannot remove a single cookie by name on Android"`. ### Method `clearByName(url: string, name: string, useWebKit: boolean)` ### Parameters #### Arguments - **url** (string) - Required - The URL whose domain should match the cookie. - **name** (string) - Required - The name of the cookie to remove. - **useWebKit** (boolean) - Required - If true, clears from `WKHTTPCookieStore`; otherwise, clears from `NSHTTPCookieStorage`. ### Response - **boolean** - `true` if a cookie was removed, `false` otherwise. ### Request Example ```javascript import CookieManager from '@preeternal/react-native-cookie-manager'; import { Platform } from 'react-native'; if (Platform.OS === 'ios') { try { const removed = await CookieManager.clearByName( 'https://app.example.com', 'session_token', false // useWebKit: false → NSHTTPCookieStorage ); console.log('Cookie removed:', removed); // true or false // Also remove from WKWebView store await CookieManager.clearByName('https://app.example.com', 'session_token', true); } catch (err) { console.error('clearByName failed:', err); } } ``` ``` -------------------------------- ### CookieManager.removeSessionCookies Source: https://context7.com/preeternal/react-native-cookie-manager/llms.txt Deletes cookies that have no expiry date (session cookies). This operation is specific to Android and is a no-op on iOS. ```APIDOC ## CookieManager.removeSessionCookies ### Description Deletes cookies that have no expiry date (i.e., session cookies that should not survive a browser restart). On iOS this is a no-op that resolves with `false`. On Android it delegates to `CookieManager.removeSessionCookies()`. ### Method `removeSessionCookies()` ### Parameters None ### Response - **removed** (boolean) - `true` if any session cookies were removed, `false` otherwise. ### Request Example ```ts import CookieManager from '@preeternal/react-native-cookie-manager'; import { Platform } from 'react-native'; async function removeSessionCookiesAndroid() { if (Platform.OS === 'android') { try { const removed = await CookieManager.removeSessionCookies(); console.log('Session cookies removed:', removed); } catch (err) { console.error('removeSessionCookies failed:', err); } } } ``` ### Response Example ```json { "removed": true } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.