PhoenixKitWeb.Integration (phoenix_kit v1.6.15)
View SourceIntegration helpers for adding PhoenixKit to Phoenix applications.
Basic Usage
Add to your router:
defmodule MyAppWeb.Router do
use MyAppWeb, :router
import PhoenixKitWeb.Integration
# Add PhoenixKit routes
phoenix_kit_routes() # Default: /phoenix_kit prefix
endAutomatic Integration
When you run mix phoenix_kit.install, the following is automatically added to your
:browser pipeline:
plug PhoenixKitWeb.Plugs.IntegrationThis plug handles all PhoenixKit features including maintenance mode, and ensures they work across your entire application
Layout Integration
Configure parent layouts in config.exs:
config :phoenix_kit,
repo: MyApp.Repo,
layout: {MyAppWeb.Layouts, :app},
root_layout: {MyAppWeb.Layouts, :root}Authentication Callbacks
Use in your app's live_sessions:
:phoenix_kit_mount_current_scope- Mounts user and scope (recommended):phoenix_kit_ensure_authenticated_scope- Requires authentication:phoenix_kit_redirect_if_authenticated_scope- Redirects if logged in
Routes Created
Authentication routes:
- /users/register, /users/log-in, /users/magic-link
- /users/settings, /users/reset-password, /users/confirm
- /users/log-out (GET/DELETE)
Admin routes (Owner/Admin only):
- /admin/dashboard, /admin/users, /admin/users/roles
- /admin/users/live_sessions, /admin/users/sessions
- /admin/settings, /admin/modules
Public pages routes (if Pages module enabled):
- {prefix}/pages/* (explicit prefix - e.g., /phoenix_kit/pages/test)
- /* (catch-all at root level - e.g., /test, /blog/post)
- Both routes serve published pages from priv/static/pages/*.md
- The catch-all can optionally serve a custom 404 markdown file when enabled
- Example: /test or /phoenix_kit/pages/test renders test.md
DaisyUI Setup
- Install:
npm install daisyui@latest - Add to tailwind.config.js:
- Content:
"../../deps/phoenix_kit" - Plugin:
require('daisyui')
- Content:
Layout Templates
Use {@inner_content} not render_slot(@inner_block):
<%!-- Correct --%>
<main>{@inner_content}</main>Scope Usage in Templates
<%= if PhoenixKit.Users.Auth.Scope.authenticated?(@phoenix_kit_current_scope) do %>
Welcome, {PhoenixKit.Users.Auth.Scope.user_email(@phoenix_kit_current_scope)}!
<% end %>
Summary
Functions
Creates locale-aware routing scopes based on enabled languages.
Functions
Creates locale-aware routing scopes based on enabled languages.
This macro generates both a localized scope (e.g., /en/) and a non-localized
scope for backward compatibility. The locale pattern is dynamically generated
from the database-stored enabled language codes.
Examples
locale_scope do
live "/admin/dashboard", DashboardLive, :index
end
# Generates routes like:
# /phoenix_kit/en/admin/dashboard (with locale)
# /phoenix_kit/admin/dashboard (without locale, defaults to "en")