Fix issue with logging out from ZTA (#2953)

This commit is contained in:
Alexandre de Souza 2025-03-06 14:55:29 -03:00 committed by GitHub
parent e49e06010a
commit 24b591825f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 10 deletions

View file

@ -3,12 +3,29 @@ defmodule LivebookWeb.UserController do
def logout(conn, _params) do
if get_session(conn, :user_id) do
conn
|> configure_session(renew: true)
|> clear_session()
|> render("logout.html")
if Livebook.Config.logout_enabled?() do
do_zta_logout(conn)
else
do_logout(conn)
end
else
redirect(conn, to: ~p"/")
end
end
defp do_logout(conn) do
conn
|> configure_session(renew: true)
|> clear_session()
|> render("logout.html")
end
defp do_zta_logout(conn) do
{_type, module, _key} = Livebook.Config.identity_provider()
case module.logout(LivebookWeb.ZTA, conn) do
:ok -> do_logout(conn)
{:error, reason} -> conn |> redirect(to: ~p"/") |> put_flash(:error, reason)
end
end
end

View file

@ -29,12 +29,7 @@ defmodule LivebookWeb.SidebarHook do
end
defp handle_info(:logout, socket) do
{_type, module, _key} = Livebook.Config.identity_provider()
case module.logout(LivebookWeb.ZTA, socket) do
:ok -> {:halt, redirect(socket, to: ~p"/logout")}
{:error, reason} -> {:cont, put_flash(socket, :error, reason)}
end
{:halt, redirect(socket, to: ~p"/logout")}
end
@connection_events ~w(hub_connected hub_changed hub_deleted)a