# `BaileysEx.Auth.Persistence`
[🔗](https://github.com/jeffhuen/baileys_ex/blob/main/lib/baileys_ex/auth/persistence.ex#L1)

Persistence behaviour for auth credentials and key-store datasets.

Phase 15 supports two built-in file backends:

- `BaileysEx.Auth.NativeFilePersistence` for the recommended durable
  Elixir-first ETF storage
- `BaileysEx.Auth.FilePersistence` for the Baileys-compatible JSON multi-file
  helper kept as a migration/compatibility bridge from Baileys JS sidecars

Custom backends can implement either the context-free callbacks, the
context-aware callbacks, or both. `BaileysEx.Auth.KeyStore` dispatches to the
widest arity the backend exports.

# `auth_state_helper`

```elixir
@type auth_state_helper() :: %{
  state: BaileysEx.Auth.State.t(),
  connect_opts: keyword(),
  save_creds: (BaileysEx.Auth.State.t() | map() -&gt; :ok | {:error, term()})
}
```

Helper map returned by the built-in auth-state loaders.

`connect_opts` is ready to merge into `BaileysEx.connect/2`, and `save_creds`
persists the latest auth-state snapshot for the selected backend.

# `delete_keys`

```elixir
@callback delete_keys(type :: atom(), id :: term()) :: :ok | {:error, term()}
```

# `delete_keys`
*optional* 

```elixir
@callback delete_keys(context :: term(), type :: atom(), id :: term()) ::
  :ok | {:error, term()}
```

# `load_credentials`

```elixir
@callback load_credentials() :: {:ok, BaileysEx.Auth.State.t()} | {:error, term()}
```

# `load_credentials`
*optional* 

```elixir
@callback load_credentials(context :: term()) ::
  {:ok, BaileysEx.Auth.State.t()} | {:error, term()}
```

# `load_keys`

```elixir
@callback load_keys(type :: atom(), id :: term()) :: {:ok, term()} | {:error, term()}
```

# `load_keys`
*optional* 

```elixir
@callback load_keys(context :: term(), type :: atom(), id :: term()) ::
  {:ok, term()} | {:error, term()}
```

# `save_credentials`

```elixir
@callback save_credentials(BaileysEx.Auth.State.t()) :: :ok | {:error, term()}
```

# `save_credentials`
*optional* 

```elixir
@callback save_credentials(context :: term(), BaileysEx.Auth.State.t()) ::
  :ok | {:error, term()}
```

# `save_keys`

```elixir
@callback save_keys(type :: atom(), id :: term(), data :: term()) ::
  :ok | {:error, term()}
```

# `save_keys`
*optional* 

```elixir
@callback save_keys(context :: term(), type :: atom(), id :: term(), data :: term()) ::
  :ok | {:error, term()}
```

---

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