# `Permit.Phoenix.Types`
[🔗](https://github.com/curiosum-dev/permit_phoenix/blob/v0.5.1/lib/permit_phoenix/types.ex#L1)

Defines types for usage with Permit in the context of Phoenix applications.

# `action_list`

```elixir
@type action_list() :: [Permit.Types.action_group()]
```

# `conn`

```elixir
@type conn() :: Plug.Conn.t()
```

# `error_msg`

```elixir
@type error_msg() :: binary()
```

A default error message for the controller in case there's no authorization.

# `fallback_path`

```elixir
@type fallback_path() :: binary()
```

A default fallback path for the controller in case there's no authorization.

# `handle_unauthorized`

```elixir
@type handle_unauthorized() :: (Permit.Types.action_group(), conn() -&gt; conn())
```

A default handler that is called in case there is no authorization.

# `hook_outcome`

```elixir
@type hook_outcome() :: {:halt, socket()} | {:cont, socket()} | no_return()
```

# `id_param_name`

```elixir
@type id_param_name() :: binary()
```

A name of a resource struct's ID parameter in controller or LiveView params, typically represented by a string.

# `live_authorization_result`

```elixir
@type live_authorization_result() ::
  {:authorized | :unauthorized | :not_found, socket()}
```

# `plug_opts`

```elixir
@type plug_opts() :: [
  authorization_module: Permit.Types.authorization_module(),
  base_query: Permit.Ecto.Types.base_query(),
  finalize_query: Permit.Ecto.Types.finalize_query(),
  resource_module: Permit.Types.resource_module(),
  preload_actions: action_list(),
  id_param_name: id_param_name(),
  except: action_list(),
  fallback_path: fallback_path(),
  error_msg: error_msg(),
  handle_unauthorized: handle_unauthorized()
]
```

- `:authorization_module` -- (Required) The app's authorization module that uses `use Permit`.
- `preload_actions` -- (Optional) The list of actions that resources will be preloaded and authorized in, in addition to :show, :delete, :edit and :update.
- `loader` -- (Required, unless :repo defined) The loader, 1-arity function, used to fetch records in singular resource functions (:show, :edit, :update, :delete and other defined as :preload_actions). It is convenient to use context getter functions as loaders.
- `resource` -- (Required) The struct module defining the specific resource the controller is dealing with.
- `id_param_name` -- (Required, if singular record actions are present) The parameter name used to look for IDs of resources, passed to the loader function or the repo.
- `fallback_path` -- (Optional) A string denoting redirect path when unauthorized. Defaults to "/".
- `error_msg` -- (Optional) An error message to put into the flash when unauthorizd. Defaults to "You do not have permission to perform this action."
- `handle_unauthorized` - (Optional) A function taking (action, conn), performing specific action when authorization is not successful. Defaults to redirecting to :fallback_path.

# `scope_subject`

```elixir
@type scope_subject() :: (map() -&gt; Permit.Types.subject()) | atom()
```

Maps the current Phoenix scope to the subject.

# `session`

```elixir
@type session() :: map()
```

# `socket`

```elixir
@type socket() :: Phoenix.LiveView.Socket.t()
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
