fix(auth): replace sign-out page with accessible custom LiveView
This commit is contained in:
parent
ba66bc15db
commit
a27425b5fb
5 changed files with 93 additions and 1 deletions
62
lib/mv_web/live/auth/sign_out_live.ex
Normal file
62
lib/mv_web/live/auth/sign_out_live.ex
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
defmodule MvWeb.SignOutLive do
|
||||
@moduledoc """
|
||||
Custom sign-out confirmation page.
|
||||
|
||||
Replaces AshAuthentication.Phoenix.SignOutLive so the page meets accessibility
|
||||
requirements (main landmark via Layouts.public_page, level-one heading) and
|
||||
uses the project's DaisyUI button styles. Submits DELETE /sign-out for CSRF
|
||||
protection, same contract as the library default.
|
||||
"""
|
||||
use Phoenix.LiveView
|
||||
use Gettext, backend: MvWeb.Gettext
|
||||
|
||||
alias Mv.Membership
|
||||
alias MvWeb.Layouts
|
||||
|
||||
@impl true
|
||||
def mount(_params, session, socket) do
|
||||
locale = session["locale"] || Application.get_env(:mv, :default_locale, "de")
|
||||
Gettext.put_locale(MvWeb.Gettext, locale)
|
||||
Gettext.put_locale(locale)
|
||||
|
||||
club_name =
|
||||
case Membership.get_settings() do
|
||||
{:ok, settings} when is_binary(settings.club_name) -> settings.club_name
|
||||
_ -> nil
|
||||
end
|
||||
|
||||
socket =
|
||||
socket
|
||||
|> assign(:sign_out_path, session["sign_out_path"] || "/sign-out")
|
||||
|> assign(:locale, locale)
|
||||
|> assign(:club_name, club_name)
|
||||
|> Layouts.assign_page_title(dgettext("auth", "Sign out"))
|
||||
|
||||
{:ok, socket}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
<Layouts.public_page flash={@flash} club_name={@club_name}>
|
||||
<div class="hero min-h-[40vh] bg-base-200 rounded-lg">
|
||||
<div class="hero-content flex-col items-start text-left">
|
||||
<div class="w-full max-w-md">
|
||||
<h1 class="text-xl font-semibold leading-8 mb-4">
|
||||
{dgettext("auth", "Sign out")}
|
||||
</h1>
|
||||
<p class="text-base-content/70 mb-4">
|
||||
{dgettext("auth", "Are you sure you want to sign out?")}
|
||||
</p>
|
||||
<.form for={%{}} action={@sign_out_path} method="delete">
|
||||
<button type="submit" class="btn btn-primary w-full">
|
||||
{dgettext("auth", "Sign out")}
|
||||
</button>
|
||||
</.form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Layouts.public_page>
|
||||
"""
|
||||
end
|
||||
end
|
||||
|
|
@ -112,7 +112,7 @@ defmodule MvWeb.Router do
|
|||
|
||||
# ASHAUTHENTICATION GENERATED AUTH ROUTES
|
||||
auth_routes AuthController, Mv.Accounts.User, path: "/auth"
|
||||
sign_out_route AuthController
|
||||
sign_out_route AuthController, "/sign-out", live_view: MvWeb.SignOutLive
|
||||
|
||||
# Remove these if you'd like to use your own authentication views
|
||||
sign_in_route register_path: "/register",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue