alik
alik

Reputation: 3870

Sharing User Session Between Multiple Domains

I am building an app which will be accessible through different domains. Depending on the domain name it is accessed from, it will behave slightly differently.

What I want to be able to do is that once someone is logged in from one domain, they should not require to register when coming from a different domain and should be automatically logged in.

My guess is that this will require sharing cookie data between domains. Can someone give pointers to how I should go about accomplishing this?

I do know that there are other website networks who do this, like http://graphicriver.net/ and http://audiojungle.net/ where you can simply log in to one and be able to use all of their sites.

Upvotes: 4

Views: 1082

Answers (1)

railscard
railscard

Reputation: 1848

config/initializers/session_store.rb

ProjectName::Application.config.session_store :cookie_store, key: '_ProjectName_session', 
                                                             domain: :all, 
                                                             tld_length: 2

And then you also need to clear cookies.

UPD: My previous answer was wrong, I've forgot to add tld_length option, so session is not shared between domains with top-level domain length more than 1 (myapp.local has a tld_length of 2). Now the answer is correct.

Upvotes: 4

Related Questions