How to share user session to different top level domains belonging to the same rails app?

Hello, I am copying my question on

I have a single rails application running on one unicorn server,
a user can register and create a public profile. This profile is under a
subdomain that the user specifies and a top level domain based on the
country of the user. For example and and so on.

The ‘appname’ part of the url does not change and the tld length based
country is not fixed. The base domain of the application is
Through that the user can access functionality like searching for public
profiles. He signs in under the domain and devise is used
user authentication.

Problem: If he visits he will
as non signed in. For * everything is ok.

How the user session gets shared across all domains of the application?
searched about it but it is not clear to me how to solve this. One thing
suspect is that the session must be stored in the database but what
with the cookies? When a user visits * and he already has
session and a cookie for *, how I know who is the user to get
his session?

Are there any common practices or gems that solve this problem?

Thanks in advance!

Did you get any solution to this?