From 8ac324f64da1a63a48ea407b3aadee5816ccddf4 Mon Sep 17 00:00:00 2001 From: reslear <12596485+reslear@users.noreply.github.com> Date: Fri, 11 Jul 2025 08:56:35 +0200 Subject: [PATCH] docs(api-key): add example on how to get user session on the server (#3333) how to get user session on server example --- docs/content/docs/plugins/api-key.mdx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/content/docs/plugins/api-key.mdx b/docs/content/docs/plugins/api-key.mdx index aab3cb7a15..bf3abf3f60 100644 --- a/docs/content/docs/plugins/api-key.mdx +++ b/docs/content/docs/plugins/api-key.mdx @@ -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. + + + ```ts + const session = await auth.api.getSession({ + headers: new Headers({ + 'x-api-key': apiKey, + }), + }); + ``` + + + + The default header key is `x-api-key`, but this can be changed by setting the `apiKeyHeaders` option in the plugin options. ```ts