Sharing a user session between multiple domains

I am creating an application that will be available across different domains. Depending on the name of the domain to which it refers, it will behave somewhat differently.

What I want to do is that as soon as someone logs in from one domain, they should not register when they arrive from another domain and should automatically register.

I assume that this will require the exchange of cookies between domains. Can someone give pointers how should I do this?

I know that there are other network of websites that do this, such as http://graphicriver.net/ and http://audiojungle.net/ , where you can simply log in and use all your sites.

+4
source share
1 answer

configurations / 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 the cookies.

UPD: my previous answer was wrong, I forgot to add the tld_length parameter, so the session is not split between domains with a top-level domain longer than 1 (myapp.local has tld_length 2). Now the answer is correct.

+4
source

Source: https://habr.com/ru/post/1382965/


All Articles