# `ExWapp.Session.Worker.PostAuth`
[🔗](https://github.com/elchemista/ex_wapp/blob/v0.1.5/lib/ex_wapp/session/worker/post_auth.ex#L1)

Post-authentication helpers triggered after the `success` node is received.

Handles LID persistence, PN↔LID mapping, prekey count queries, and
prekey upload logic.

# `handle_digest_response`

```elixir
@spec handle_digest_response(
  ExWapp.Binary.Node.t(),
  String.t(),
  map(),
  (-&gt; ExWapp.Binary.Node.t())
) ::
  {map(), list()}
```

Handles the response to the digest query and finalizes post-auth.

# `handle_passive_response`

```elixir
@spec handle_passive_response(
  ExWapp.Binary.Node.t(),
  String.t(),
  map(),
  (-&gt; ExWapp.Binary.Node.t()),
  (-&gt; ExWapp.Binary.Node.t())
) :: {map(), list()}
```

Handles the response to SetPassive(false) and finalizes post-auth by default.

Digest validation can be re-enabled with `runtime: [protocol: [post_auth_digest_enabled: true]]`.

# `handle_prekey_count_response`

```elixir
@spec handle_prekey_count_response(
  ExWapp.Binary.Node.t(),
  map(),
  (-&gt; ExWapp.Binary.Node.t())
) ::
  {map(), list()}
```

Handles the prekey count response from the server and decides whether to upload.

Returns `{state, actions}`.

# `handle_prekey_upload_response`

```elixir
@spec handle_prekey_upload_response(
  ExWapp.Binary.Node.t(),
  String.t(),
  map(),
  (-&gt; ExWapp.Binary.Node.t())
) :: {map(), list()}
```

Handles the response to a prekey upload IQ.

# `persist_lid_and_mapping`

```elixir
@spec persist_lid_and_mapping(
  ExWapp.Session.Worker.t(),
  ExWapp.JID.t() | binary() | nil
) ::
  ExWapp.Session.Worker.t()
```

Persists the LID value from the success node and creates own PN↔LID mapping.

# `refill_from_notification`

```elixir
@spec refill_from_notification(ExWapp.Session.Worker.t(), non_neg_integer()) ::
  {ExWapp.Session.Worker.t(), list()}
```

Refills the server prekey pool after an `encrypt` inventory notification.

The upload restores the pool toward the configured initial size instead of
adding only a tiny fixed batch. An already in-flight upload is left alone.

# `start`

```elixir
@spec start(ExWapp.Session.Worker.t(), (-&gt; ExWapp.Binary.Node.t())) ::
  {ExWapp.Session.Worker.t(), list()}
```

Starts the post-auth flow after receiving the `success` node.

To preserve live inbound delivery, the activation path mirrors the older
working runtime sequence:
1. query prekey count
2. send `SetPassive(false)` immediately
3. send `presence type="available"` immediately
4. upload prekeys later only if the server count requires it

Digest validation remains available as an explicit opt-in, but it is disabled
by default because some fresh-pair sessions are being invalidated immediately
after the digest IQ is sent.

---

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