Alexander V.
Alexander V.

Reputation: 73

How to detect user across different websites?

In the company I'm currently working at there are multiple WebApps, e.g: App1, App2, App3 ... The current issue is that we want to allow an user to log into App1, and if he goes to App2 we do not require this user to login again, because he already logged in App1.

How can I achieve this? I'm using Firebase but the onAuthChange() doesn't track changes on different domains, and I'm aware I cannot share cookies from App1.com to App2.com.

My plan was to once a user signs in in App1, I create a cookie on the browser that I could check on App2 and if there is a current user, get the ID and fetch the data needed to render the user information.

I'm working with: ReactJs, NodeJs, Graphql, Prisma, Nexus, Firebase (Auth). In case it matters

Upvotes: 0

Views: 127

Answers (1)

Apps
Apps

Reputation: 3389

Cookies are not shared across different domains. But if the sites app1, app2, app3 have a common sub domain, then they can share the cookies. For example app1.example.com, app2.example.com, app3.example.com. All these sites have *.example.com as their sub-domain. So a cookie set for *.example.com can be accessed by all these web-apps. These web-apps need to have a common authentication mechanism shared among them.

Another option is when you authenticate with app1, then response can include cookies for all three domains.

Upvotes: 1

Related Questions