Packages
ash_authentication_phoenix
2.4.8
3.0.0-rc.9
3.0.0-rc.8
3.0.0-rc.7
3.0.0-rc.6
3.0.0-rc.4
3.0.0-rc.3
3.0.0-rc.2
3.0.0-rc.1
3.0.0-rc.0
2.17.2
2.17.1
2.17.0
2.16.0
2.15.0
2.14.1
2.14.0
2.13.1
2.13.0
2.12.2
2.12.1
2.12.0
2.11.0
2.10.5
2.10.4
2.10.3
2.10.2
2.10.1
2.10.0
2.9.0
2.8.0
2.7.0
2.6.3
2.6.2
2.6.1
2.6.0
2.5.4
2.5.3
2.5.2
2.5.1
2.5.0
2.4.8
2.4.7
2.4.6
2.4.5
2.4.4
2.4.3
2.4.2
2.4.1
2.4.0
2.3.0
2.2.1
2.2.0
2.1.11
2.1.10
2.1.9
2.1.8
2.1.7
2.1.6
2.1.5
2.1.4
2.1.3
2.1.2
2.1.1
2.1.0
2.0.2
2.0.1
2.0.0
2.0.0-rc.2
2.0.0-rc.1
2.0.0-rc.0
1.9.4
1.9.3
1.9.2
1.9.1
1.9.0
1.8.7
1.8.6
1.8.5
1.8.4
1.8.3
1.8.2
1.8.1
1.8.0
1.7.3
1.7.2
1.7.1
1.7.0
1.6.6
1.6.5
1.6.4
1.6.3
1.6.2
1.6.1
1.6.0
1.5.1
1.5.0
1.4.8
1.4.7
1.4.6
1.4.5
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.3.1
1.3.0
1.2.0
1.1.0
1.0.1
1.0.0
Phoenix integration for Ash Authentication
Security advisory:
This version has known vulnerabilities.
View advisories
Current section
Files
Jump to
Current section
Files
lib/ash_authentication_phoenix/overrides.ex
defmodule AshAuthentication.Phoenix.Overrides do
@moduledoc """
Behaviour for overriding component styles and attributes in your application.
The default implementation is `AshAuthentication.Phoenix.Overrides.Default`
which uses [TailwindCSS](https://tailwindcss.com/) to generate a fairly
generic looking user interface.
You can override this by adding your own override modules to the
`AshAuthentication.Phoenix.Router.sign_in_route/1` macro in your router:
```elixir
sign_in_route overrides: [MyAppWeb.AuthOverrides, AshAuthentication.Phoenix.Overrides.Default]
```
and defining `lib/my_app_web/auth_overrides.ex` within which you can set any
overrides.
The `use` macro defines overridable versions of all callbacks which return
`nil`, so you only need to define the functions that you care about.
Each of the override modules specified in the config will be called in the
order that they're specified, so you can still use the defaults if you just
override some properties.
```elixir
defmodule MyAppWeb.AuthOverrides do
use AshAuthentication.Phoenix.Overrides
alias AshAuthentication.Phoenix.Components
override Components.Banner do
set :image_url, "/images/sign_in_logo.png"
end
end
```
"""
@doc false
@spec __using__(any) :: Macro.t()
defmacro __using__(_env) do
quote do
require AshAuthentication.Phoenix.Overrides
import AshAuthentication.Phoenix.Overrides, only: :macros
Module.register_attribute(__MODULE__, :override, accumulate: true)
@component nil
@before_compile AshAuthentication.Phoenix.Overrides
end
end
@doc """
Define overrides for a specific component.
"""
@spec override(component :: module, do: Macro.t()) :: Macro.t()
defmacro override(component, do: block) do
quote do
@component unquote(component)
unquote(block)
end
end
@doc """
Override a setting within a component.
"""
@spec set(atom, any) :: Macro.t()
defmacro set(selector, value) do
quote do
@override {@component, unquote(selector), unquote(value)}
end
end
@doc false
@spec __before_compile__(any) :: Macro.t()
defmacro __before_compile__(env) do
overrides =
env.module
|> Module.get_attribute(:override, [])
|> Map.new(fn {component, selector, value} -> {{component, selector}, value} end)
|> Macro.escape()
quote do
def overrides do
unquote(overrides)
end
end
end
end