Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log when navigate fails #3526

Merged
merged 1 commit into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/phoenix_live_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,8 @@ defmodule Phoenix.LiveView do
immediately invoked to handle the change of params and URL state.
Then the new state is pushed to the client, without reloading the
whole page while also maintaining the current scroll position.
For live navigation to another LiveView, use `push_navigate/2`.
For live navigation to another LiveView in the same `live_session`,
use `push_navigate/2`. Otherwise, use `redirect/2`.
## Options
Expand All @@ -1051,7 +1052,7 @@ defmodule Phoenix.LiveView do
end

@doc """
Annotates the socket for navigation to another LiveView.
Annotates the socket for navigation to another LiveView in the same `live_session`.
The current LiveView will be shutdown and a new one will be mounted
in its place, without reloading the whole page. This can
Expand Down
17 changes: 15 additions & 2 deletions lib/phoenix_live_view/channel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1532,10 +1532,23 @@ defmodule Phoenix.LiveView.Channel do
defp authorize_session(%Session{} = session, endpoint, %{"redirect" => url}) do
if redir_route = session_route(session, endpoint, url) do
case Session.authorize_root_redirect(session, redir_route) do
{:ok, %Session{} = new_session} -> {:ok, new_session, redir_route, url}
{:error, :unauthorized} = err -> err
{:ok, %Session{} = new_session} ->
{:ok, new_session, redir_route, url}

:error ->
Logger.warning(
"navigate event to #{inspect(url)} failed because you are redirecting across live_sessions. " <>
"A full page reload will be performed instead"
)

{:error, :unauthorized}
end
else
Logger.warning(
"navigate event to #{inspect(url)} failed because the URL does not point to a LiveView. " <>
"A full page reload will be performed instead"
)

{:error, :unauthorized}
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/phoenix_live_view/session.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ defmodule Phoenix.LiveView.Session do
{:ok, replace_root(session, route.view, self())}

true ->
{:error, :unauthorized}
:error
end
end

Expand Down
Loading