@amazon-devices/react-native-cookies library provides a way for React Native applications to manage cookies.
A cookie is a small piece of data stored on the user’s device by the web browser while browsing a website. Cookies are designed to be a reliable mechanism for websites to remember stateful information or to record the user’s browsing activity.
Installation
-
Add the JavaScript library dependency in the
package.jsonfile: -
Reinstall dependencies using the
npm installcommand.
Example
The following example shows all methods already implemented in this library.API reference
See the official README from the @react-native-cookies/cookies GitHub repository. The following list shows the current state of implemented functionalities.- When no
domainfield is specified for the Cookie object, a URL host is used instead. - When no
pathis specified for the Cookie object, an empty path/is assumed. - Setting
useWebKit = trueon the Vega platform, for any of the methods that accepts the parameter, is a no-op. If no value is provided,useWebKitdefaults tofalse. - Passing a malformed URL, to any methods that accept a URL, returns an error message.
Known issues and limitations
- The accepted date-time format for the
expiresfield of a Cookie object is the ISO8601 format with an offset from UTC. After a cookie is set on Vega, the date-time is always converted to GMT. For example, aftermockedCookiefrom the previous example is set, subsequent retrievals return a timestamp ofexpires: '2030-06-01T17:30:00.00Z'. This timestamp is the equivalent time in GMT. - When session cookies (cookies with no
expiresfield) are retrieved withget, theexpiresfield is populated with1970-01-01T00:00:00Z. If this cookie is used with other Cookie Managers, remove the field from the cookie. Otherwise, the cookie is read as expired by other Cookie Manager implementations (such as Webview Cookie Manager).

