Skip to content

Commit 76e5b7f

Browse files
Update Ecto Sandbox doc for when on_mount hooks on live_session are present (#188)
1 parent a9e8829 commit 76e5b7f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib/phoenix_ecto/sql/sandbox.ex

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,21 @@ defmodule Phoenix.Ecto.SQL.Sandbox do
125125
end
126126
end
127127
128+
If you have `on_mount` hooks in `live_session` defined in your `router.ex`
129+
(for example, routes requiring authentication after running `mix phx.gen.auth`
130+
to generate your authentication system), make sure the `MyApp.LiveAcceptance`
131+
hook runs before, so following hooks have access to the Ecto Sandbox:
132+
133+
live_session :require_authenticated_user,
134+
on_mount:
135+
if(Application.compile_env(:your_app, :sql_sandbox),
136+
do: [MyAppWeb.AcceptanceHook],
137+
else: []
138+
) ++ [{MyAppWeb.UserAuth, :ensure_authenticated}] do
139+
live "/users/settings", UserSettingsLive, :edit
140+
live "/users/settings/confirm_email/:token", UserSettingsLive, :confirm_email
141+
end
142+
128143
## Concurrent end-to-end tests with external clients
129144
130145
Concurrent and transactional tests for external HTTP clients is supported,

0 commit comments

Comments
 (0)