0
votes

I am developing multi-tenant rails app without using apartment gem. I have a problem with user authentication using devise.

When I sign up my user session is not shared across all subdomains. I found that I need to change session configuration and here is how looks my config:

Rails.application.config.session_store :cookie_store, key: '_hyggebulk_session', domain: 'lvh.me', tld_length: 2

here is my routes.rb:

Rails.application.routes.draw do
  devise_for :users, controllers: { registrations: "registrations" }

  constraints(SubdomainRequired) do
    root to: "backend/dashboard#index", as: :authenticated_root
  end

  root to: "backend/dashboard#index"
end

I think that there is some little problem with my code, so please help me.

1
What is the "little problem?" What happens, versus what you expect to happen? - MarsAtomic
I expect my authenticate user is shared across all subdomain but for now devise session is not shared across subdomains - Mišel Ademi

1 Answers

1
votes

You just need to add the domains on which you want to share your session/cookie

Rails.application.config.session_store :cookie_store, key: '_hyggebulk_session', domain: '*.lvh.me', tld_length: 2

Or do something like:

Rails.application.config.session_store :cookie_store, key: '_hyggebulk_session', domain: ['subdomain1.lvh.me', 'subdomain2.lvh.me'], tld_length: 2