Grab my user's tenant name so I can display it

I am currently doing something like this in order to grab my user's tenant. Is this the correct approach?
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_live_flash
plug :put_root_layout, html: {VezaWeb.Layouts, :root}
plug :protect_from_forgery
plug :put_secure_browser_headers
plug :load_from_session
plug VezaWeb.Plugs.SetTenant # This is where I set the tenant via custom plug
end
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_live_flash
plug :put_root_layout, html: {VezaWeb.Layouts, :root}
plug :protect_from_forgery
plug :put_secure_browser_headers
plug :load_from_session
plug VezaWeb.Plugs.SetTenant # This is where I set the tenant via custom plug
end
I am a little concerned that I am hitting the database every time a users visits any page but I think this is actually the recommend way right? Now, I would like to display my user's organization name in the front end but I am wondering.. is there a way to fetch the user's org once maybe at sign in, instead of doing it on every liveview visit?
Solution:
sign in does not share state with your liveview, but you can put the tenant name in the session
Jump to solution
1 Reply
Solution
Oliver
Oliver3w ago
sign in does not share state with your liveview, but you can put the tenant name in the session

Did you find this page helpful?