GithubHelp home page GithubHelp logo

shimohq / react-native-cookie Goto Github PK

View Code? Open in Web Editor NEW
92.0 10.0 49.0 68 KB

A cookie manager module for react-native

License: MIT License

JavaScript 15.62% Java 31.92% Objective-C 44.29% Starlark 6.19% Ruby 1.98%

react-native-cookie's Introduction

react-native-cookie

A cookie manager module for react-native(Supports for both iOS and Android).

Installation

# install library from npm
npm install react-native-cookie --save

# for RN 0.60 and above
cd ios/ && pod install

# for RN 0.59 and below
react-native link react-native-cookie

Usage

Import

import Cookie from 'react-native-cookie';

Get

Cookie.get(url:String, name?: String): Promise<Object|String>

// get all cookies which are belonged to 'http://bing.com/'
Cookie.get('http://bing.com/').then((cookie) => console.log(cookie));

// get cookie named 'foo' from 'http://bing.com/'
Cookie.get('http://bing.com/', 'foo').then((cookie) => console.log(cookie));

Set

Cookie.set(url:String, name: String, value: any, options?: Object): Promise

Options

The following options are available for now

  • domain Specifies the value for the Domain Set-Cookie attribute. By default, no domain is set, and most clients will consider the cookie to apply to only the current domain.

  • expires Specifies the Date object to be the value for the Expires Set-Cookie attribute. By default, no expiration is set, and most clients will consider this a "non-persistent cookie" and will delete it on a condition like exiting a web browser application.

  • path Specifies the value for the Path Set-Cookie attribute. By default, the path is considered the "default path". By default, no maximum age is set, and most clients will consider this a "non-persistent cookie" and will delete it on a condition like exiting a web browser application

// set cookie 'foo=bar' for 'http://bing.com/'
Cookie.set('http://bing.com/', 'foo', 'bar').then(() => console.log('success'));

// set cookie 'foo=bar' for 'http://bing.com/' with options:
Cookie.set('http://bing.com/', 'foo', 'bar', {
    path: 'ditu',
    domain: 'cn.bing.com'
}).then(() => console.log('success'));

Clear

Cookie.clear(url?: String): Promise

// clear all cookies for all domains
Cookie.clear();

// clear all cookies for 'http://bing.com'
Cookie.clear('http://bing.com');

react-native-cookie's People

Contributors

duckduckgo-eng avatar fpetitit avatar magicismight avatar maisonsport-fleigh avatar sericaia avatar xenorplxx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-cookie's Issues

Link command breaks Xcode project file.

I used the link command to link the native libraries.
react-native link react-native-cookie

The link command finished successfully without any errors or warnings but the Xcode project file broke. Project /../../../project.xcodeproj cannot be opened because the project file cannot be parsed.

I did not encounter any problems when adding the library manually.

cookies are not persistent (android)

Hi,
I have used the code as you explained.
Please check the issue that i am getting.

Here is my code,
Cookie.get(StagingUrl,"connect.sid").then((cookie) => {

  console.log(cookie)
 

});

Getting Null when app restarts ? whats the issue.

Broken for Android on React-Native v47

Hi, thank you for the development of this useful library.

After upgrading my project from React-Native 0.46.1 -> 0.47.1, the compilation for Android fails with this error :

:react-native-cookie:compileReleaseJavaWithJavac - is not incremental (e.g. outputs have 
changed, no previous execution, etc.).
[...]/node_modules/react-native-
cookie/android/src/main/java/im/shimo/react/cookie/CookieManagerPackage.java:27: error: 
method does not override or implement a method from a supertype
    @Override
    ^
Note: [...]/node_modules/react-native-
cookie/android/src/main/java/im/shimo/react/cookie/CookieManagerModule.java uses or
overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error
:react-native-cookie:compileReleaseJavaWithJavac FAILED

cookie for browser

I set cookie and work when fetch or open webview, but I open browser(safari, chrome) it not work. how set cookie for browser(like safari, chrome...)

Exception '*** -[__NSDictionaryM setObject:forKey:]: object cannot be nil (key: OriginURL)' was thrown while invoking setCookie on target RNCookieManager with params

On iOS when I try to set a cookie, I got the following exception, with the stack trace below:

Exception '*** -[__NSDictionaryM setObject:forKey:]: object cannot be nil (key: OriginURL)' was thrown while invoking setCookie on target RNCookieManager with params (
    "192.168.1.203",
    "cookie_name",
    "cookie_value",
        {
    },
    14,
    15
)
callstack: (
	0   CoreFoundation                      0x000000010556612b __exceptionPreprocess + 171
	1   libobjc.A.dylib                     0x00000001039bbf41 objc_exception_throw + 48
	2   CoreFoundation                      0x00000001055a60cc _CFThrowFormattedException + 194
	3   CoreFoundation                      0x000000010547a74a -[__NSDictionaryM setObject:forKey:] + 986
	4   Garvisor                            0x00000001024c9e84 -[RNCookieManager setCookie:name:value:props:resolver:rejecter:] + 340
	5   CoreFoundation                      0x00000001054ea36c __invoking___ + 140
	6   CoreFoundation                      0x00000001054ea240 -[NSInvocation invoke] + 320
	7   CoreFoundation                      0x0000000105502c26 -[NSInvocation invokeWithTarget:] + 54
	8   Garvisor                            0x00000001022bdbbc -[RCTModuleMethod invokeWithBridge:module:arguments:] + 2796
	9   Garvisor                            0x0000000102354532 _ZN8facebook5reactL11invokeInnerEP9RCTBridgeP13RCTModuleDatajRKN5folly7dynamicE + 786
	10  Garvisor                            0x000000010235405f _ZZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEiENK3$_0clEv + 127
	11  Garvisor                            0x0000000102353fd9 ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 25
	12  libdispatch.dylib                   0x000000010a4752f7 _dispatch_call_block_and_release + 12
	13  libdispatch.dylib                   0x000000010a47633d _dispatch_client_callout + 8
	14  libdispatch.dylib                   0x000000010a47e855 _dispatch_queue_serial_drain + 1162
	15  libdispatch.dylib                   0x000000010a47f1ea _dispatch_queue_invoke + 336
	16  libdispatch.dylib                   0x000000010a47af7c _dispatch_queue_override_invoke + 733
	17  libdispatch.dylib                   0x000000010a482102 _dispatch_root_queue_drain + 772
	18  libdispatch.dylib                   0x000000010a481da0 _dispatch_worker_thread3 + 132
	19  libsystem_pthread.dylib             0x000000010a93d5a2 _pthread_wqthread + 1299
	20  libsystem_pthread.dylib             0x000000010a93d07d start_wqthread + 13

I already did the linking manually, but It's still not working.

Android Compilation Error

A problem occurred configuring project ':app'.

Could not resolve all dependencies for configuration ':app:_debugApk'.
A problem occurred configuring project ':react-native-cookie'.
> Failed to notify project evaluation listener.
> com.android.build.gradle.tasks.factory.AndroidJavaCompile.setDependencyCacheDir(Ljava/io/File;)V

Any ideas?

[Unhandled promise rejection: TypeError: undefined is not an object (evaluating '_reactNative.NativeModules.RNCookieManager.clearCookie')]

I get an error while using

Cookie.clear().then(() => {
                console.log('Cookie cleared');
});

Npm: 4.2
Node: 7.10.1
React-native-cli: 2.0.1
React-native: 0.50.3

Logs are as follows:

 [Unhandled promise rejection: TypeError: undefined is not an object (evaluating '_reactNative.NativeModules.RNCookieManager.clearCookie')]
- node_modules\react-native-cookie\cookie.android.js:22:44 in clear$
- node_modules\regenerator-runtime\runtime.js:63:44 in tryCatch
- node_modules\regenerator-runtime\runtime.js:337:30 in invoke
- node_modules\regenerator-runtime\runtime.js:96:28 in <unknown>
- node_modules\regenerator-runtime\runtime.js:63:44 in tryCatch
- node_modules\regenerator-runtime\runtime.js:139:28 in invoke
- node_modules\regenerator-runtime\runtime.js:184:17 in <unknown>
- node_modules\promise\setimmediate\core.js:45:7 in tryCallTwo
- node_modules\promise\setimmediate\core.js:200:23 in doResolve
- node_modules\promise\setimmediate\core.js:66:12 in Promise
- node_modules\regenerator-runtime\runtime.js:183:27 in callInvokeWithMethodAndArg
- node_modules\regenerator-runtime\runtime.js:206:12 in enqueue
- node_modules\regenerator-runtime\runtime.js:96:28 in <unknown>
- node_modules\regenerator-runtime\runtime.js:226:8 in async
- node_modules\react-native-cookie\cookie.android.js:6:15 in clear
* app\src\js\authentication\LoginScreen.js:108:8 in doLogIn
- node_modules\react-proxy\modules\createPrototypeProxy.js:44:35 in proxiedMethod
* app\src\js\authentication\LoginScreen.js:79:35 in onPress
- node_modules\react-native\Libraries\Components\Touchable\TouchableNativeFeedback.android.js:170:45 in touchableHandlePress
- node_modules\react-native\Libraries\Components\Touchable\Touchable.js:746:34 in _performSideEffectsForTransition
- ... 24 more stack frames from framework internals

Requires android 7.1?

Not an issue but a question.
Does it have to use android 7.1?
Any possibility for it to work with lower versions?

TypeError: option expires is invalid

Hi, I am using this package but getting a error:

Error:

YellowBox.js:71 Possible Unhandled Promise Rejection (id: 0):
TypeError: option expires is invalid
TypeError: option expires is invalid

Build error for iOS Info.plist not found

Hi, while using it for ios i get following build error

** BUILD FAILED **

The following commands produced analyzer issues:

Analyze Base/RCTModuleMethod.mm normal x86_64
(1 command with analyzer issues)

The following build commands failed:
ProcessInfoPlistFile /Users/user/Documents/app/ios/build/Build/Products/Debug-iphonesimulator/RNCookieManagerTests.xctest/Info.plist RNCookieManagerTests/Info.plist
(1 failure)

Installing build/Build/Products/Debug-iphonesimulator/MYAPP.app
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=2):
Failed to install the requested application
An application bundle was not found at the provided path.
Provide a valid path to the desired application bundle.
Print: Entry, ":CFBundleIdentifier", Does Not Exist

Looks like Info.plist is required but not found in the project, is it something I have to create for this library specifically ?

How to get expires data?

I'm new to cookie, so please close this issue if it is not relate.
My problem is, when using this line:

Cookie.get('http://abc.com/').then((cookie) => console.log(cookie));

I can get the cookie like this: {"ss-pid": "GMj......"} but without expires data. How can I get the expires data?

The file “Info.plist” couldn’t be opened because there is no such file.

Full error log

ProcessInfoPlistFile /Users/mahwd/Library/Developer/Xcode/DerivedData/Emlak-axbhkufzzmyetdgozayrkkdyyksh/Build/Products/Debug-iphonesimulator/RNCookieManagerTests.xctest/Info.plist RNCookieManagerTests/Info.plist
cd /Users/mahwd/Desktop/projects/emdk/edmk/node_modules/react-native-cookie/ios
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
builtin-infoPlistUtility /Users/mahwd/Desktop/projects/emdk/edmk/node_modules/react-native-cookie/ios/RNCookieManagerTests/Info.plist -expandbuildsettings -format binary -platform iphonesimulator -o /Users/mahwd/Library/Developer/Xcode/DerivedData/Emlak-axbhkufzzmyetdgozayrkkdyyksh/Build/Products/Debug-iphonesimulator/RNCookieManagerTests.xctest/Info.plist

error: could not read data from '/Users/mahwd/Desktop/projects/emdk/edmk/node_modules/react-native-cookie/ios/RNCookieManagerTests/Info.plist': The file “Info.plist” couldn’t be opened because there is no such file.

screen shot 2018-10-13 at 18 06 29

screen shot 2018-10-13 at 18 11 07

SYSTEM INFO

Environment:
OS: macOS High Sierra 10.13.6
Node: 8.9.4
Yarn: 1.9.4
npm: 5.6.0
Watchman: 4.9.0
Xcode: Xcode 9.4.1 Build version 9F2000
Android Studio: 3.2 AI-181.5540.7.32.5014246

Packages: (wanted => installed)
react: 16.3.1 => 16.3.1
react-native: 0.55.4 => 0.55.4

Do not url-encode cookies

I want to set a cookie that's a json object, but the set method keeps URL encoding the string. The code that parses the cookie is out of my control: I need to set the cookie non-url-encoded but there seems to be no way to do this.

wkwebview support

hello,

I noticed that for webkit=true cookie related action are not working

is there a solution available?

Dirk

Undefined is not an object (evaluating Cookiemanager.clearCookies)

When i click on logout button and press on 'Yes', it shows this error.
I have also done 'react-native link react-native-cookie', but still shows this error.

Importing Files
import InstagramLogin from 'react-native-instagram-login';
import Cookie from 'react-native-cookie';

Logout Code
`toggleInstagram= () => {
const {instagram}= this.state;

    if(instagram)
        Alert.alert(
        '',
        'Are you sure you want to remove Instagram account?',
        [
            {
                text: 'Yes', onPress: () => {
                  Cookie.clear().then(() => {
                    this.setState({ token: null, instagram:null, instagram_data:null })
                  })
            } },
            {text: 'No', style: 'cancel'}
        ]
    );

    else
        return this.refs.instagramLogin.show();
}`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.