2
  • React Native V 0.56 for Android
  • Rails 5.1.3 API Only

My Rails app was able to persist session, but suddenly after upgrading React Native to 0.56 the Rails is creating a new session every time on each api request.

Unable to understand why the session is getting reset each time.

My application.rb looks like this

module AppService
    class Application < Rails::Application
        config.load_defaults 5.1
        config.middleware.use ActionDispatch::Flash
        config.middleware.use Rack::MethodOverride
        config.middleware.use ActionDispatch::Cookies

        config.api_only = true
        config.middleware.use ActionDispatch::Session::CookieStore, key: '_namespace_key'
    end
end

Can someone please point out what can be the issue? How can I debug this?

UPDATE Digging a bit deeper I came across this https://github.com/facebook/react-native/pull/19770

Seems like this is a bug with RN 0.56. Can someone please suggest how this can be solved?

red-devil
  • 1,064
  • 1
  • 20
  • 34

1 Answers1

2

I got a very similar problem and the issue was, as part of React Native V 0.56 upgrade, I also had to upgrade my nodejs version to 8. In node8 (may be even in prior versions) fetch() needs credentials: 'include' option to send cookies with requests. Not having the session cookies in your request could be the reason why your sever is creating a new session every time.

fetch(url, { method: 'GET', credentials: 'include' })

This SO question and answers may shed more light into the problem and solution.

obai
  • 399
  • 5
  • 14
  • For me this is working with android and not with iOS. – red-devil Jan 11 '19 at 18:50
  • For other readers, this issue again occurs with latest version i.e. 0.57 RN in iOS. More info here.. https://stackoverflow.com/questions/54163056/cookies-set-in-a-redirect-response-are-not-persisted – red-devil Jan 12 '19 at 19:28