I have defined an authentication pipeline like so in my routers.ex file which go through the Authenticate plug I have defined in my plugs directory
pipeline :authentication do
plug MyAppWeb.Plugs.Authenticate
end
And in the call function of this plug I’m conditionally setting the current_user inside the session like so:
def call(conn, default) do
current_user = authenticate_user(conn.params, conn |> get_session(:current_user))
conn |> put_session(:current_user, current_user)
end
This does the authentication part for me and the private routes are only available if current_user exists in the session.
While this works, when I open a new tab I have go through the authentication part all over again to get the current_user in the session.
How do, in general, make the session I’ve set in a tab I’m currently on available in all the new tabs that might open?
Which browser(s) this is happening in? You are sure you are not using Firefox with the thing that isolates tabs on?
It is not browser specific as such. The session is not available when I open a new tab once it has already been set. I tried it with different browsers.
Once authenticated, the session is only available in the tab it was set on.
So you go to second tab and it presents you with login page?
If this happens, and you refresh your original tab - are you still signed in there?
Yes, If I refresh that tab, I’m still signed in. But when I open a new tab I’m not signed in
I figured it out. Sorry about this 
Looks like it is available in all tabs. In one of the tabs I had it open on 127.0.0.1:4000 and in all the other tabs that I was opening I had it open on localhost:4000
even though they point to the same process, they are essentially different domain names. and session cookies are domain name specific.
Thanks for the help 
1 Like
Ah yes, that would do it. Glad you figured it out!