Skip to content

Commit

Permalink
Update Ecto Sandbox doc for when on_mount hooks on live_session a…
Browse files Browse the repository at this point in the history
…re present (#188)
  • Loading branch information
basilenouvellet authored Mar 6, 2025
1 parent a9e8829 commit 76e5b7f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/phoenix_ecto/sql/sandbox.ex
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,21 @@ defmodule Phoenix.Ecto.SQL.Sandbox do
end
end
If you have `on_mount` hooks in `live_session` defined in your `router.ex`
(for example, routes requiring authentication after running `mix phx.gen.auth`
to generate your authentication system), make sure the `MyApp.LiveAcceptance`
hook runs before, so following hooks have access to the Ecto Sandbox:
live_session :require_authenticated_user,
on_mount:
if(Application.compile_env(:your_app, :sql_sandbox),
do: [MyAppWeb.AcceptanceHook],
else: []
) ++ [{MyAppWeb.UserAuth, :ensure_authenticated}] do
live "/users/settings", UserSettingsLive, :edit
live "/users/settings/confirm_email/:token", UserSettingsLive, :confirm_email
end
## Concurrent end-to-end tests with external clients
Concurrent and transactional tests for external HTTP clients is supported,
Expand Down

0 comments on commit 76e5b7f

Please sign in to comment.