react-native-cookies
react-native-cookies copied to clipboard
Cannot read cookies set in react-native from rails server
I have asked the following question on stack overflow with no answer, so am asking here. I am using react-native-cookies. I can use the getAll method to read cookies that have been previously set on the server side. In react native I can use the set command to set a cookie called 'myCookie', and I can read it using the getAll command. However, I cannot read a cookie on the server side that has been set by the react-native app.
The react-native code which is in index.ios.js
var CookieManager = require('react-native-cookies')
componentWillMount () {
CookieManager.set({
name: 'myCookie',
value: 'myValue',
domain: 'ios app',
origin: 'some origin',
path: '/',
version: '1',
expiration: '2017-05-30T12:30:00.00-05:00'
}, (err, res) => {
console.log('cookie set!');
console.log(err);
console.log(res);
console.log('my output');
});
CookieManager.getAll((cookie) => {
let isAuthenticated;
if (cookie && cookie.remember_token) {
isAuthenticated = true;
}
else {
isAuthenticated = false;
}
this.setState({
loggedIn: isAuthenticated
});
console.log('GM:cookie remember isAuthenticated', cookie.remember_token, isAuthenticated,this.state.title,'myCookie',cookie.myCookie)
});
},
The output from the last console log message is
GM:cookie remember isAuthenticated Object {domain: "localhost", value: "BAhbB2kHSSJFZmM3NDVkNTEwZTBkYTViZjU4NTJhOGQyZDNlMz…wY6BkVU--5888c15b42c6bdf3ca34c89f6554d2455d48c46b", name: "remember_token", path: "/"} true Sign In myCookie Object {domain: "ios app", value: "myValue", name: "myCookie", path: "/"}
showing that the myCookie object is being set and that the app is able to recover the remember_token set by the rails server.
The above code is executed at start up of the ios app. The ios app then opens a webview component that calls the new method in the sessions controller of a ruby on rails web app. In the rails sessions controller, I find that cookie['myCookie']
is nil
. Why is the cookie being set in a way that I cannot access it from the rails app?
Someone has suggested dropping the optional keys like domain and origin, but react-native-cookie appears to require all these keys. I have also tried setting the domain to the correct domain name and that does not help either.
+1
Have you already found a solution for this? Thx.
Unfortunately no.