Aludel.Web.Resolver behaviour (aludel v0.1.18)

Copy Markdown View Source

Behavior for customizing dashboard access and user identification.

Host applications can implement this behavior to control who can access the dashboard, identify users, and customize refresh rates.

Example

defmodule MyApp.AludelResolver do
  @behaviour Aludel.Web.Resolver

  @impl true
  def resolve_user(conn) do
    conn.assigns[:current_user]
  end

  @impl true
  def resolve_access(user) do
    if user && user.role == :admin, do: :all, else: :read_only
  end

  @impl true
  def resolve_refresh(_user) do
    15
  end
end

Then configure it in your router:

use Aludel.Web, :router,
  resolver: MyApp.AludelResolver

Default Behavior

If no custom resolver is configured, the defaults are:

  • resolve_user/1 returns nil
  • resolve_access/1 returns :all
  • resolve_refresh/1 returns 5

Summary

Callbacks

Resolves the access level for a user.

Resolves the refresh interval in seconds for a user.

Resolves the current user from the connection.

Functions

Calls a resolver callback with fallback to default implementation.

Callbacks

resolve_access(user)

@callback resolve_access(user :: term()) :: :all | :read_only

Resolves the access level for a user.

Return :all for full access or :read_only for restricted access.

resolve_refresh(user)

@callback resolve_refresh(user :: term()) :: pos_integer()

Resolves the refresh interval in seconds for a user.

resolve_user(conn)

@callback resolve_user(conn :: Plug.Conn.t()) :: term()

Resolves the current user from the connection.

Return nil if no user is authenticated.

Functions

call_with_fallback(resolver, callback, args)

@spec call_with_fallback(module(), atom(), list()) :: term()

Calls a resolver callback with fallback to default implementation.

If the resolver module implements the callback, it is called with the given args. Otherwise, the default implementation is used.