> ## Documentation Index
> Fetch the complete documentation index at: https://developers.telnyx.com/llms.txt
> Use this file to discover all available pages before exploring further.

# onConnect()

> `protected` **onConnect**(`_conn`): `Promise`\<`void`>

Hook: a client connection is established. Override to authorize, seed, or
close the connection. The default implementation does nothing.

When the connection surface is active (an `authorize` / `onAttach` /
`webSocket` override) and this hook is overridden, the default
[`webSocket`](/docs/agent-sdk/interface/webSocket) runs it once per new connection —
before authorization or any snapshot — with a context carrying the
upgrade request (`req`) and a `close` to reject the connection. Frames a
fast client sends while this gate is pending are buffered and replayed
in order once the connection is admitted. Overriding this hook alone
does NOT activate the connection surface. For claims-based decisions
prefer [`authorize`](/docs/agent-sdk/interface/authorize) and
[`onAttach`](/docs/agent-sdk/interface/onAttach), which run with the connection's
resolved claims.

**Parameters**

| Parameter | Type | Description |
| - | - | - |
| `_conn` | `unknown` | The connection context: `{ req, close }` on the default connection surface. |

**Returns**

`Promise`\<`void`>
