docs(api-key): add example on how to get user session on the server (#3333)

how to get user session on server example
This commit is contained in:
reslear
2025-07-11 08:56:35 +02:00
committed by GitHub
parent 6e4c2fe563
commit 8ac324f64d

View File

@@ -369,6 +369,19 @@ This function will delete all API keys that have an expired expiration date.
Any time an endpoint in Better Auth is called that has a valid API key in the headers, we will automatically create a mock session to represent the user.
<Tabs items={['Server']}>
<Tab value="Server">
```ts
const session = await auth.api.getSession({
headers: new Headers({
'x-api-key': apiKey,
}),
});
```
</Tab>
</Tabs>
The default header key is `x-api-key`, but this can be changed by setting the `apiKeyHeaders` option in the plugin options.
```ts