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

# Authentication

> Learn how to protect your Nexus server with authentication

## Setup

Nexus comes with a query-parameter based authentication [middleware](/features/middleware). It is disabled by default. To enable it, you need to set the `rpcAuthKey` config in the Nexus configuration. Alternatively, you can set the `NEXUS_RPC_AUTH_KEY` environment variable.

```typescript theme={null}
import {
  Nexus,
  NodeProvider,
  CHAIN,
} from "@whatsgood/nexus";

const llamaRpcNodeProvider = new NodeProvider({
  name: "llama-rpc",
  chain: CHAIN.ETHEREUM_MAINNET,
  url: "https://eth.llamarpc.com",
});


const nexus = Nexus.create({
  // ...
  port: 4000,
  nodeProviders: [llamaRpcNodeProvider],
  rpcAuthKey: 'my-secret-key',
});
```

## Usage

Once you set the `rpcAuthKey` config, you can start the server and access it with the `?key` query parameter.

<Snippet file="send-a-request-with-auth.mdx" />
