All threads / Share session across multiple Rails micro-services using CookieStore
Ask A Question

Notifications

You’re not receiving notifications from this thread.

Share session across multiple Rails micro-services using CookieStore

Thomas Pedersen asked in General

Has anyone successfully made multiple Rails 6 applications share the same session cookie? I have two applications: login and admin. Login authenticates the user and sets a session cookie after which it redirects the user to admin. Everything is running through Kong Gateway on port 80 like this.

kong:80
+---> login:3001
+---> admin:3002

I have made sure credentials.yml.enc and the cookie_store key are the same in both repos. The cookie is also transmitted correctly through Kong, so the problem doesn't seem to be there. However, when the browser hits admin, the session is reset. What am I missing?

As a test I tried the same setup with ActiveRecord session store, which works flawlessly.

Thomas

I think I have this working properly, but I have had a few random errors occasionally. I think what fixed it is setting the domain to the proper value. Otherwise, each subdomain has its own cooke.

Rails.application.config.session_store :cookie_store, key: "app-name_session", domain: “.thedomain.tld", expire_after: 1.week
Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 64,380+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2022 GoRails, LLC. All rights reserved.