We have a Rails app which is the main site, but we created a separate app in Golang that handles a lot of other real-time functionalities like Video and Audio Calls, Messaging and Whiteboard sections.
The problem we have now is we don't know how to share web sessions between the 2 apps. When you switch in between the Rails app to Golang. Just like going from Gmail to Google Drive to YouTube, the session remains the same even though these apps run in different subdomains and sometimes different languages.
I was able to add the session from Rails + Devise/Warden into the browser cookie but the cookie is encrypted. How do I decrypt or use this cookie to authenticate the user in Go?
Could you guys please share with me how you would approach solving this problem in your own app?
Using this answer I was able to get the session cookie to appear both in the main site in React + Rails and the subdomain in React + Golang, but the cookie is encrypted, how do we decrypt/get the values in there? for example the user_id?
You can share the session between two backends (regardless of the backends) using redis
datastore as central shared memory.
So, whenever you create a new session in Rails
or Go
app:
a59eb448-d268-413e-a837-b5aefc65a4b2
redis
with that unique session id (a59eb448-d268-413e-a837-b5aefc65a4b2
).rails.mydomain.com
and go.mydomain.com
then you need to make the cookie accessible from both subdomains *.mydomain.com
.This way you can have shared session across different subdomains in the client side using cookies and shared across different backends in the server side using redis.