phoenix-liveview-auth

Installation
SKILL.md

Phoenix LiveView Authentication

RULES — Follow these with no exceptions

  1. Always use on_mount callbacks for LiveView auth — never check auth in mount/3 directly; on_mount runs before mount and centralizes auth logic
  2. Use mount_current_scope/2 to extract scope from session — never access session tokens manually or parse session data in LiveViews
  3. Handle both :cont and :halt returns from on_mount:halt must redirect with a flash message, never silently drop the connection
  4. Resolve import conflicts explicitlyPhoenix.Controller and Phoenix.LiveView both export redirect/2 and put_flash/3; use except: to avoid ambiguity
  5. Use bracket access assigns[:current_scope] in templates — dot access @current_scope crashes on nil when user is not authenticated
  6. Test auth redirects by asserting {:error, {:redirect, %{to: path}}} — don't test auth by checking rendered content; verify the redirect tuple from live/2
  7. Define on_mount hooks once, reference via live_session in router — never duplicate auth logic across LiveView modules

on_mount Authentication Pattern

The standard pattern for LiveView authentication. Define once, use everywhere via live_session.

Related skills
Installs
1
GitHub Stars
118
First Seen
Apr 21, 2026