mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-30 19:06:47 -05:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user