red-devil
red-devil

Reputation: 1103

Rails 5 Api Only with React Native New Session Id Each Time

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?

Upvotes: 2

Views: 397

Answers (1)

obai
obai

Reputation: 417

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.

Upvotes: 2

Related Questions