{"id":26566231,"url":"https://github.com/react-native-cookies/cookies","last_synced_at":"2025-04-12T21:19:06.969Z","repository":{"id":38175314,"uuid":"232921311","full_name":"react-native-cookies/cookies","owner":"react-native-cookies","description":"🍪 Cookie Manager for React Native","archived":false,"fork":false,"pushed_at":"2024-07-11T23:59:51.000Z","size":425,"stargazers_count":496,"open_issues_count":84,"forks_count":97,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-05T04:30:02.695Z","etag":null,"topics":["android","cookies","ios","react-native"],"latest_commit_sha":null,"homepage":"","language":"Java","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/react-native-cookies.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-09T22:51:10.000Z","updated_at":"2025-03-25T12:18:06.000Z","dependencies_parsed_at":"2023-02-18T03:45:20.498Z","dependency_job_id":null,"html_url":"https://github.com/react-native-cookies/cookies","commit_stats":null,"previous_names":["react-native-community/cookies","react-native-community/react-native-cookies"],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-native-cookies%2Fcookies","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-native-cookies%2Fcookies/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-native-cookies%2Fcookies/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-native-cookies%2Fcookies/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/react-native-cookies","download_url":"https://codeload.github.com/react-native-cookies/cookies/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248631878,"owners_count":21136582,"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","react-native"],"created_at":"2025-03-22T18:19:32.162Z","updated_at":"2025-04-12T21:19:06.949Z","avatar_url":"https://github.com/react-native-cookies.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# React Native Cookies - A Cookie Manager for React Native\n\nCookie Manager for React Native\n\n\u003ca href=\"https://discord.gg/CJHKVeW6sp\"\u003e\n\u003cimg src=\"https://img.shields.io/discord/764994995098615828?label=Discord\u0026logo=Discord\u0026style=for-the-badge\"\n            alt=\"chat on Discord\"\u003e\u003c/a\u003e\n\nThis module was ported from [joeferraro/react-native-cookies](https://github.com/joeferraro/react-native-cookies). This would not exist without the work of the original author, [Joe Ferraro](https://github.com/joeferraro).\n\n## Important notices \u0026 Breaking Changes\n- **v6.0.0**: Package name updated to `@react-native-cookies/cookies`.\n- **v5.0.0**: Peer Dependency of \u003e= React Native 0.60.2\n- **v4.0.0**: Android SDK version bumpted to 21\n- **v3.0.0**: Remove React Native Core dependencies, CookieManager.set() support for Android\n- **v2.0.0**: Package name updated to `@react-native-community/cookies`.\n\n## Maintainers\n\n- [Jason Safaiyeh](https://github.com/safaiyeh) ([Twitter @safaiyeh](https://twitter.com/safaiyeh)) from [🪄 Magic Eden](https://magiceden.io)\n\n## Platforms Supported\n\n- ✅ iOS\n- ✅ Android\n- ❌ Currently lacking support for Windows, macOS, and web. Support for these platforms will be created when there is a need for them. Starts with a posted issue.\n\n## Expo\n\n- ✅ You can use this library with [Development Builds](https://docs.expo.dev/development/introduction/). No config plugin is required.\n- ❌ This library can't be used in the \"Expo Go\" app because it [requires custom native code](https://docs.expo.dev/workflow/customizing/).\n\n## Installation\n\n```\nyarn add @react-native-cookies/cookies\n```\n\nThen link the native iOS package\n\n```\nnpx pod-install\n```\n\n## Usage\n\nA cookie object can have one of the following fields:\n\n```typescript\nexport interface Cookie {\n  name: string;\n  value: string;\n  path?: string;\n  domain?: string;\n  version?: string;\n  expires?: string;\n  secure?: boolean;\n  httpOnly?: boolean;\n}\n\nexport interface Cookies {\n  [key: string]: Cookie;\n}\n```\n\n```javascript\nimport CookieManager from '@react-native-cookies/cookies';\n\n// set a cookie\nCookieManager.set('http://example.com', {\n  name: 'myCookie',\n  value: 'myValue',\n  domain: 'some domain',\n  path: '/',\n  version: '1',\n  expires: '2015-05-30T12:30:00.00-05:00'\n}).then((done) =\u003e {\n  console.log('CookieManager.set =\u003e', done);\n});\n\n*NB:* When no `domain` is specified, url host will be used instead.\n*NB:* When no `path` is specified, an empty path `/` will be assumed.\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((success) =\u003e {\n      console.log('CookieManager.setFromResponse =\u003e', success);\n    });\n\n// Get cookies for a url\nCookieManager.get('http://example.com')\n  .then((cookies) =\u003e {\n    console.log('CookieManager.get =\u003e', cookies);\n  });\n\n// list cookies (IOS ONLY)\nCookieManager.getAll()\n  .then((cookies) =\u003e {\n    console.log('CookieManager.getAll =\u003e', cookies);\n  });\n\n// clear cookies\nCookieManager.clearAll()\n  .then((success) =\u003e {\n    console.log('CookieManager.clearAll =\u003e', success);\n  });\n\n// clear a specific cookie by its name (IOS ONLY)\nCookieManager.clearByName('http://example.com', 'cookie_name')\n  .then((success) =\u003e {\n    console.log('CookieManager.clearByName =\u003e', success);\n  });\n\n// flush cookies (ANDROID ONLY)\nCookieManager.flush()\n  .then((success) =\u003e {\n    console.log('CookieManager.flush =\u003e', success);\n  });\n\n// Remove session cookies (ANDROID ONLY)\n// Session cookies are cookies with no expires set. Android typically does not\n// remove these, it is up to the developer to decide when to remove them.\n// The return value is true if any session cookies were removed.\n// iOS handles removal of session cookies automatically on app open.\nCookieManager.removeSessionCookies()\n  .then((sessionCookiesRemoved) =\u003e {\n    console.log('CookieManager.removeSessionCookies =\u003e', sessionCookiesRemoved);\n  });\n```\n\n### WebKit-Support (iOS only)\n\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\nPrior to WebKit-Support, cookies would have been stored in `NSHTTPCookieStorage` and sharedCookiesEnabled must be set on webviews to ensure access to them.\n\nWith WebKit-Support, cookies are stored in a separate webview store `WKHTTPCookieStore` and not necessarily shared with other http requests. Caveat is that this store is available upon mounting the component but not necessarily prior so any attempts to set a cookie too early may result in a false positive.\n\nTo use WebKit-Support, you should be able to simply make advantage of the react-native-webview as is OR alternatively use the webview component like [react-native-wkwebview](https://github.com/CRAlpha/react-native-wkwebview).\n\nTo use this _CookieManager_ with WebKit-Support we extended the interface with the attribute `useWebKit` (a boolean value, default: `FALSE`) 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| clearByName | Yes            | `CookieManager.clearByName(url:string, name: string, useWebKit:boolean)` |\n| get         | Yes            | `CookieManager.get(url:string, useWebKit:boolean)`                       |\n| set         | Yes            | `CookieManager.set(url:string, cookie:object, useWebKit:boolean)`        |\n\n##### Usage\n\n```javascript\nimport CookieManager from '@react-native-cookies/cookies';\n\nconst useWebKit = true;\n\n// list cookies (IOS ONLY)\nCookieManager.getAll(useWebKit)\n\t.then((cookies) =\u003e {\n\t\tconsole.log('CookieManager.getAll from webkit-view =\u003e', cookies);\n\t});\n\n// clear cookies\nCookieManager.clearAll(useWebKit)\n\t.then((succcess) =\u003e {\n\t\tconsole.log('CookieManager.clearAll from webkit-view =\u003e', succcess);\n\t});\n\n// clear cookies with name (IOS ONLY)\nCookieManager.clearByName('http://example.com', 'cookie name', useWebKit)\n\t.then((succcess) =\u003e {\n\t\tconsole.log('CookieManager.clearByName from webkit-view =\u003e', succcess);\n  });\n\n// Get cookies as a request header string\nCookieManager.get('http://example.com', useWebKit)\n\t.then((cookies) =\u003e {\n\t\tconsole.log('CookieManager.get from webkit-view =\u003e', cookies);\n\t});\n\n// set a cookie\nconst newCookie: = {\n\tname: 'myCookie',\n\tvalue: 'myValue',\n\tdomain: 'some domain',\n\tpath: '/',\n\tversion: '1',\n\texpires: '2015-05-30T12:30:00.00-05:00'\n};\n\nCookieManager.set('http://example.com', newCookie, useWebKit)\n\t.then((res) =\u003e {\n\t\tconsole.log('CookieManager.set from webkit-view =\u003e', res);\n\t});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freact-native-cookies%2Fcookies","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freact-native-cookies%2Fcookies","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freact-native-cookies%2Fcookies/lists"}