Skip to content

foloinfo/react-native-cookies

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-cookies

Cookie manager for react native.

Installation

IOS

  1. npm install react-native-cookies
  2. In the XCode's "Project navigator", right click on project name folder ➜ Add Files to <...>
  • Ensure Copy items if needed and Create groups are checked
  1. Go to node_modulesreact-native-cookies ➜ add RNCookieManagerIOS folder
  2. Compile and have some cookies

android

  1. npm install react-native-cookies
  2. rnpm link react-native-cookies - (run npm install -g rnpm if required)
  3. Om nom nom nom cookies.

Usage

var CookieManager = require('react-native-cookies');

// set a cookie (IOS ONLY)
CookieManager.set({
  name: 'myCookie',
  value: 'myValue',
  domain: 'some domain',
  origin: 'some origin',
  path: '/',
  version: '1',
  expiration: '2015-05-30T12:30:00.00-05:00'
}, (err, res) => {
  console.log('cookie set!');
  console.log(err);
  console.log(res);
});

// Set cookies from a response header
// This allows you to put the full string provided by a server's Set-Cookie 
// response header directly into the cookie store.
CookieManager.setFromResponse('http://example.com', 'user_session=abcdefg; path=/; expires=Thu, 1 Jan 2030 00:00:00 -0000; secure; HttpOnly', (res) => {
  // `res` will be true or false depending on success.
  console.log("Set cookie", res);
})

// Get cookies as a request header string
CookieManager.get('http://example.com', (err, res) => {
  console.log('Got cookies for url', res);
  // Outputs 'user_session=abcdefg; path=/;'
})

// list cookies (IOS ONLY)
CookieManager.getAll((err, res) => {
  console.log('cookies!');
  console.log(err);
  console.log(res);
});

// clear cookies
CookieManager.clearAll((err, res) => {
  console.log('cookies cleared!');
  console.log(err);
  console.log(res);
});

Roadmap

  • Proper getAll dictionary by domain
  • Proper error handling
  • Anything else?

PR's welcome!

About

Cookie manager for React Native

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 48.1%
  • Objective-C 40.2%
  • JavaScript 11.7%