react-native-cookiemanager icon indicating copy to clipboard operation
react-native-cookiemanager copied to clipboard

cookies are not persistent

Open mallikarjunakp opened this issue 8 years ago • 9 comments

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

Here is my code,

var options = { name: 'username', value: 'abcdefg', domain: 'http://localhost:8081/', origin: 'http://localhost:8081/', path: '/', expiration: 'Thu, 18 Dec 2016 12:00:00 UTC', }; CookieManager.default.set(options,(res) => { alert("Set cookie"+res); });

I am executing this on click of a button for testing.

Then i am using the below code to get cookie CookieManager.default.getAll((res) => { alert(JSON.stringify(res)); });

But then the cookie is null. it alerts me this {}

mallikarjunakp avatar Aug 19 '16 07:08 mallikarjunakp

try change there

CookieManager.default.set(map,(res) => {
alert("Set cookie"+res);
});

to

CookieManager.set(map,(res) => {
alert("Set cookie"+res);
});

shexiaoheng avatar Aug 19 '16 07:08 shexiaoheng

I have done that before. But it says undefined is not a function evaluating the CookieManager.set And then i debugged and consoled the CookieManager object, I have got to know that set function is inside default object. So i changed. It works and gives me that success. But when i do getAll, i am getting no result

mallikarjunakp avatar Aug 19 '16 07:08 mallikarjunakp

HI, thanks for the reply, I am sorry that i didn't observe the flow. Now i am able to set and get the cookies. but once the app is restart then cookies are gone. Is n't it persistent ?

mallikarjunakp avatar Aug 19 '16 07:08 mallikarjunakp

you mean callback(res) ?

shexiaoheng avatar Aug 19 '16 08:08 shexiaoheng

No. What I meant was, I did set the cookie, and then cookies are available throughout the app. But once i close the app and open it again, and try to access the cookies, they are no more. So the persistent problem :(

mallikarjunakp avatar Aug 19 '16 08:08 mallikarjunakp

After the repair finished bug I'll release a new version

shexiaoheng avatar Aug 19 '16 08:08 shexiaoheng

@mallikarjunakp I made the following changes set(options,callback) -> setCookie(options) getAll(callback) -> getCookie() clearAll(callback) -> removeAllCookies()

shexiaoheng avatar Aug 19 '16 10:08 shexiaoheng

v0.2.0

Hello, same problem on Android: When I pass following data to setCookie:

{
domain:"https://example.com/"
expiration:""
name:"auth"
origin:"same origin"
path:"/"
value:"1"
}

I got following from getCookie (parsed):

{auth:"0", ...}

Here is my code: https://gist.github.com/iegik/21633e999aa653b0f046cc31138cdc5b

PS: I write my own mixed class from both react-native-cookies and react-native-cookiemanager

Update:

{
domain:""
expiration:""
name:"auth"
origin:""
path:""
value:"1"
}
  • same result

Do You check these properties for empty value?

iegik avatar May 04 '17 17:05 iegik

https://gist.github.com/jacobtabak/78e226673d5a6a4c4367

iegik avatar May 04 '17 17:05 iegik