Changing host subdomain and persist conn / session

I created a Multi Tenant app with allowed “subdomains”.
Each tenant has a subdomain (ex: aaa.app.local), and I can log in with “parent” user account.
When I change from aaa.app.local to bbb.app.local a new conn / session is started, and I have to log in again.
Is possible to mantain/persist conn / session (maybe with changed conn.host) after this action?

PS: Elixir 1.5, Phoenix 1.3.

2 Likes

I think %Plug.Conn{} is created anew for each request, so there might not be much reason to persist it.

In order to persist a session, you probably need to add a cookie header like

Set-Cookie: name=value; domain=app.local

I would guess that’s what :domain option in Plug.Session is for, but I might be wrong.

See https://stackoverflow.com/questions/18492576/share-cookie-between-subdomain-and-domain for more.

3 Likes

Thanks. It worked!
I edited endpoint.ex and my auth plug.

/lib/myapp_web/endpoint.ex

  ...
  plug Plug.Session,
    ..
    domain: ".app.local",
    ...
2 Likes

Hi, I am wondering what you did to your auth plug?