All Projects → joeferraro → React Native Cookies

joeferraro / React Native Cookies

Licence: mit
Cookie manager for React Native

Projects that are alternatives of or similar to React Native Cookies

Mapbox Android Demo
Google Play demo app for the Mapbox Maps SDK for Android
Stars: ✭ 624 (-20.41%)
Mutual labels:  mobile
Awesome Tensorflow Lite
TensorFlow Lite models, samples, tutorials, tools and learning resources.
Stars: ✭ 676 (-13.78%)
Mutual labels:  mobile
Ribs
Uber's cross-platform mobile architecture framework.
Stars: ✭ 6,641 (+747.07%)
Mutual labels:  mobile
Lunar Unity Console
High-performance Unity iOS/Android logger built with native platform UI
Stars: ✭ 628 (-19.9%)
Mutual labels:  mobile
Cordova Plugin File
Apache Cordova Plugin file
Stars: ✭ 664 (-15.31%)
Mutual labels:  mobile
Framework7 Vue
Deprecated! Build full featured iOS & Android apps using Framework7 & Vue
Stars: ✭ 682 (-13.01%)
Mutual labels:  mobile
Electrode Native
A platform to ease integration&delivery of React Native apps in existing mobile applications
Stars: ✭ 606 (-22.7%)
Mutual labels:  mobile
Crboxinputview
Verify code input view. Support security type for password.短信验证码输入框,支持密文模式
Stars: ✭ 749 (-4.46%)
Mutual labels:  mobile
Frida Scripts
A collection of my Frida.re instrumentation scripts to facilitate reverse engineering of mobile apps.
Stars: ✭ 665 (-15.18%)
Mutual labels:  mobile
Ring
Innovative and practical general-purpose multi-paradigm language
Stars: ✭ 716 (-8.67%)
Mutual labels:  mobile
Processing Android
Processing mode and core library to create Android apps with Processing
Stars: ✭ 643 (-17.98%)
Mutual labels:  mobile
Slinky
A light-weight, responsive, mobile-like navigation menu plugin
Stars: ✭ 649 (-17.22%)
Mutual labels:  mobile
Swiper
Most modern mobile touch slider with hardware accelerated transitions
Stars: ✭ 29,519 (+3665.18%)
Mutual labels:  mobile
Jfoenix
JavaFX Material Design Library
Stars: ✭ 5,720 (+629.59%)
Mutual labels:  mobile
Embeddinator 4000
Tools to turn .NET libraries into native libraries that can be consumed on Android, iOS, Mac, Linux and other platforms.
Stars: ✭ 735 (-6.25%)
Mutual labels:  mobile
Cordova Plugin Wkwebview Engine
[DEPRECATED] Apache Cordova wkwebview engine plugin
Stars: ✭ 607 (-22.58%)
Mutual labels:  mobile
Turtlebot3
ROS packages for Turtlebot3
Stars: ✭ 673 (-14.16%)
Mutual labels:  mobile
Elide
Elide is a Java library that lets you stand up a GraphQL/JSON-API web service with minimal effort.
Stars: ✭ 766 (-2.3%)
Mutual labels:  mobile
Qr Filetransfer
Transfer files over WiFi between your computer and your smartphone from the terminal
Stars: ✭ 738 (-5.87%)
Mutual labels:  mobile
Ng Zorro Antd Mobile
A configurable Mobile UI components based on Ant Design Mobile and Angular. 🐜
Stars: ✭ 709 (-9.57%)
Mutual labels:  mobile

react-native-cookies

Cookie manager for react native.

npm version npm downloads GitHub license

This project has moved

This project has been moved to the React Native Community.

Installation

yarn add react-native-cookies

Linking

Automatic (recommended)

react-native link react-native-cookies

Manual

If automatic linking does not work, you can manually link this library by following the instructions below:

iOS
  1. Open your project in Xcode, right click on Libraries and click Add Files to "Your Project Name" Look under node_modules/react-native-cookies/ios and add RNCookieManagerIOS.xcodeproj.
  2. Add libRNCookieManagerIOS.a to `Build Phases -> Link Binary With Libraries.
  3. Clean and rebuild your project
Android

Run react-native link to link the react-native-cookies library.

Or if you have trouble, make the following additions to the given files manually:

android/settings.gradle

include ':react-native-cookies'
project(':react-native-cookies').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-cookies/android')

android/app/build.gradle

dependencies {
   ...
   compile project(':react-native-cookies')
}

MainApplication.java

On top, where imports are:

import com.psykar.cookiemanager.CookieManagerPackage;

Add the CookieManagerPackage class to your list of exported packages.

@Override
protected List<ReactPackage> getPackages() {
    return Arrays.asList(
            new MainReactPackage(),
            new CookieManagerPackage()
    );
}

Usage

import CookieManager from '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'
}).then((res) => {
  console.log('CookieManager.set =>', 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')
    .then((res) => {
      // `res` will be true or false depending on success.
      console.log('CookieManager.setFromResponse =>', res);
    });

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

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

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

// clear a specific cookie by its name (IOS ONLY)
CookieManager.clearByName('cookie_name')
  .then((res) => {
    console.log('CookieManager.clearByName =>', res);
  });

WebKit-Support (iOS only)

React 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.

To use this it's required to use a special implementation of the WebView component (e.g. react-native-wkwebview).

This special implementation of the WebView component stores the cookies not in NSHTTPCookieStorage anymore. The new cookie-storage is WKHTTPCookieStore and implementes a differnt interface.

To use this CookieManager with WebKit-Support we extended the interface with the attribute useWebKit (a boolean value, default: FASLE) for the following methods:

Method WebKit-Support Method-Signature
getAll Yes CookieManager.getAll(useWebKit:boolean)
clearAll Yes CookieManager.clearAll(useWebKit:boolean)
get Yes CookieManager.get(url:string, useWebKit:boolean)
set Yes CookieManager.set(cookie:object, useWebKit:boolean)
Usage
import CookieManager from 'react-native-cookies';

const useWebKit = true;

// list cookies (IOS ONLY)
CookieManager.getAll(useWebKit)
	.then((res) => {
		console.log('CookieManager.getAll from webkit-view =>', res);
	});

// clear cookies
CookieManager.clearAll(useWebKit)
	.then((res) => {
		console.log('CookieManager.clearAll from webkit-view =>', res);
	});

// Get cookies as a request header string
CookieManager.get('http://example.com', useWebKit)
	.then((res) => {
		console.log('CookieManager.get from webkit-view =>', res);
		// => 'user_session=abcdefg; path=/;'
	});

// set a cookie (IOS ONLY)
const newCookie: = {
	name: 'myCookie',
	value: 'myValue',
	domain: 'some domain',
	origin: 'some origin',
	path: '/',
	version: '1',
	expiration: '2015-05-30T12:30:00.00-05:00'
};

CookieManager.set(newCookie, useWebKit)
	.then((res) => {
		console.log('CookieManager.set from webkit-view =>', res);
	});

TODO

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

PR's welcome!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].