{"id":13476635,"url":"https://github.com/joeferraro/react-native-cookies","last_synced_at":"2025-03-27T03:30:37.438Z","repository":{"id":32821936,"uuid":"36414841","full_name":"joeferraro/react-native-cookies","owner":"joeferraro","description":"Cookie manager for React Native","archived":true,"fork":false,"pushed_at":"2020-01-23T18:47:22.000Z","size":117,"stargazers_count":789,"open_issues_count":85,"forks_count":317,"subscribers_count":21,"default_branch":"master","last_synced_at":"2024-02-12T17:04:36.057Z","etag":null,"topics":["android","cookies","ios","mobile","react","react-native"],"latest_commit_sha":null,"homepage":null,"language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joeferraro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-28T04:33:08.000Z","updated_at":"2024-02-12T17:04:36.058Z","dependencies_parsed_at":"2022-09-05T16:10:08.060Z","dependency_job_id":null,"html_url":"https://github.com/joeferraro/react-native-cookies","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeferraro%2Freact-native-cookies","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeferraro%2Freact-native-cookies/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeferraro%2Freact-native-cookies/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joeferraro%2Freact-native-cookies/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joeferraro","download_url":"https://codeload.github.com/joeferraro/react-native-cookies/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245778282,"owners_count":20670682,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","cookies","ios","mobile","react","react-native"],"created_at":"2024-07-31T16:01:32.806Z","updated_at":"2025-03-27T03:30:36.990Z","avatar_url":"https://github.com/joeferraro.png","language":"Objective-C","readme":"## react-native-cookies\n\nCookie manager for react native.\n\n[![npm version](https://badge.fury.io/js/react-native-cookies.svg)](https://badge.fury.io/js/react-native-cookies)\n[![npm downloads](https://img.shields.io/npm/dm/react-native-cookies.svg)](https://www.npmjs.com/package/react-native-cookies)\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/joeferraro/react-native-cookies/master/LICENSE.md)\n\n## This project has moved\n\nThis project has been moved to the [React Native Community](https://github.com/react-native-community/react-native-cookies).\n\n### Installation\n\n```\nyarn add react-native-cookies\n```\n\n### Linking\n\n#### Automatic (recommended)\n\n```\nreact-native link react-native-cookies\n```\n\n#### Manual\n\nIf automatic linking does not work, you can manually link this library by following the instructions below:\n\n##### iOS\n\n1. Open your project in Xcode, right click on `Libraries` and click `Add\n   Files to \"Your Project Name\"` Look under `node_modules/react-native-cookies/ios` and add `RNCookieManagerIOS.xcodeproj`.\n2. Add `libRNCookieManagerIOS.a` to `Build Phases -\u003e Link Binary With Libraries.\n3. Clean and rebuild your project\n\n##### Android\n\nRun `react-native link` to link the react-native-cookies library.\n\nOr if you have trouble, make the following additions to the given files manually:\n\n**android/settings.gradle**\n\n```gradle\ninclude ':react-native-cookies'\nproject(':react-native-cookies').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-cookies/android')\n```\n\n**android/app/build.gradle**\n\n```gradle\ndependencies {\n   ...\n   compile project(':react-native-cookies')\n}\n```\n\n**MainApplication.java**\n\nOn top, where imports are:\n\n```java\nimport com.psykar.cookiemanager.CookieManagerPackage;\n```\n\nAdd the `CookieManagerPackage` class to your list of exported packages.\n\n```java\n@Override\nprotected List\u003cReactPackage\u003e getPackages() {\n    return Arrays.asList(\n            new MainReactPackage(),\n            new CookieManagerPackage()\n    );\n}\n```\n\n\n\n### Usage\n\n```javascript\nimport CookieManager from 'react-native-cookies';\n\n// set a cookie (IOS ONLY)\nCookieManager.set({\n  name: 'myCookie',\n  value: 'myValue',\n  domain: 'some domain',\n  origin: 'some origin',\n  path: '/',\n  version: '1',\n  expiration: '2015-05-30T12:30:00.00-05:00'\n}).then((res) =\u003e {\n  console.log('CookieManager.set =\u003e', res);\n});\n\n// Set cookies from a response header\n// This allows you to put the full string provided by a server's Set-Cookie \n// response header directly into the cookie store.\nCookieManager.setFromResponse(\n  'http://example.com', \n  'user_session=abcdefg; path=/; expires=Thu, 1 Jan 2030 00:00:00 -0000; secure; HttpOnly')\n    .then((res) =\u003e {\n      // `res` will be true or false depending on success.\n      console.log('CookieManager.setFromResponse =\u003e', res);\n    });\n\n// Get cookies as a request header string\nCookieManager.get('http://example.com')\n  .then((res) =\u003e {\n    console.log('CookieManager.get =\u003e', res); // =\u003e 'user_session=abcdefg; path=/;'\n  });\n\n// list cookies (IOS ONLY)\nCookieManager.getAll()\n  .then((res) =\u003e {\n    console.log('CookieManager.getAll =\u003e', res);\n  });\n\n// clear cookies\nCookieManager.clearAll()\n  .then((res) =\u003e {\n    console.log('CookieManager.clearAll =\u003e', res);\n  });\n\n// clear a specific cookie by its name (IOS ONLY)\nCookieManager.clearByName('cookie_name')\n  .then((res) =\u003e {\n    console.log('CookieManager.clearByName =\u003e', res);\n  });\n\n```\n\n#### WebKit-Support (iOS only)\nReact Native comes with a WebView component, which uses UIWebView on iOS. Introduced in iOS 8 Apple implemented the WebKit-Support with all the performance boost. \n\nTo use this it's required to use a special implementation of the WebView component (e.g. [react-native-wkwebview](https://github.com/CRAlpha/react-native-wkwebview)).\n\nThis special implementation of the WebView component stores the cookies __not__ in `NSHTTPCookieStorage` anymore. The new cookie-storage is `WKHTTPCookieStore` and implementes a differnt interface.\n\nTo use this _CookieManager_ with WebKit-Support we extended the interface with the attribute `useWebKit` (a boolean value, default: `FASLE`) for the following methods:\n\n|Method|WebKit-Support|Method-Signature|\n|---|---|---|\n|getAll| Yes | `CookieManager.getAll(useWebKit:boolean)` |\n|clearAll| Yes | `CookieManager.clearAll(useWebKit:boolean)` |\n|get| Yes | `CookieManager.get(url:string, useWebKit:boolean)` |\n|set| Yes | `CookieManager.set(cookie:object, useWebKit:boolean)` |\n\n##### Usage\n```javascript\nimport CookieManager from 'react-native-cookies';\n\nconst useWebKit = true;\n\n// list cookies (IOS ONLY)\nCookieManager.getAll(useWebKit)\n\t.then((res) =\u003e {\n\t\tconsole.log('CookieManager.getAll from webkit-view =\u003e', res);\n\t});\n\n// clear cookies\nCookieManager.clearAll(useWebKit)\n\t.then((res) =\u003e {\n\t\tconsole.log('CookieManager.clearAll from webkit-view =\u003e', res);\n\t});\n\n// Get cookies as a request header string\nCookieManager.get('http://example.com', useWebKit)\n\t.then((res) =\u003e {\n\t\tconsole.log('CookieManager.get from webkit-view =\u003e', res);\n\t\t// =\u003e 'user_session=abcdefg; path=/;'\n\t});\n\n// set a cookie (IOS ONLY)\nconst newCookie: = {\n\tname: 'myCookie',\n\tvalue: 'myValue',\n\tdomain: 'some domain',\n\torigin: 'some origin',\n\tpath: '/',\n\tversion: '1',\n\texpiration: '2015-05-30T12:30:00.00-05:00'\n};\n\nCookieManager.set(newCookie, useWebKit)\n\t.then((res) =\u003e {\n\t\tconsole.log('CookieManager.set from webkit-view =\u003e', res);\n\t});\n```\n\n### TODO\n\n- Proper `getAll` dictionary by domain\n- Proper error handling\n- Anything else?\n\nPR's welcome!\n","funding_links":[],"categories":["Objective-C","\u003ca name=\"Network:-Native-Modules\"\u003eNetwork: Native Modules\u003c/a\u003e"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoeferraro%2Freact-native-cookies","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoeferraro%2Freact-native-cookies","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoeferraro%2Freact-native-cookies/lists"}