mirror of
https://github.com/better-auth/better-auth.git
synced 2026-10-19 11:24:57 -05:00
docs: update 1.5 release notes for api-keys (#8222)
This commit is contained in:
@@ -269,6 +269,87 @@ export const auth = betterAuth({
|
||||
- **Provider CRUD endpoints**: List, get, update, and delete SSO providers via API.
|
||||
- **Shared OIDC redirect URI**: Single redirect URI for all OIDC providers.
|
||||
|
||||
---
|
||||
|
||||
### API Key Plugin
|
||||
|
||||
The API Key plugin has received some major improvements.
|
||||
|
||||
We've extracted the plugin into it's own package, install it via:
|
||||
|
||||
```package-install
|
||||
npm install @better-auth/api-key
|
||||
```
|
||||
|
||||
And update your imports!
|
||||
|
||||
```diff title="auth.ts"
|
||||
- import { apiKey } from "better-auth/plugins";
|
||||
+ import { apiKey } from "@better-auth/api-key";
|
||||
```
|
||||
|
||||
```diff title="auth-client.ts"
|
||||
- import { apiKeyClient } from "better-auth/client/plugins";
|
||||
+ import { apiKeyClient } from "@better-auth/api-key/client";
|
||||
```
|
||||
|
||||
#### Organization owned API Keys
|
||||
|
||||
Long awaited support for organization-owned API keys has been added.
|
||||
You can now create API keys that are owned by organizations instead of users.
|
||||
|
||||
```ts
|
||||
import { apiKey } from "@better-auth/api-key";
|
||||
|
||||
export const auth = betterAuth({
|
||||
plugins: [apiKey({ references: "organization" })],
|
||||
});
|
||||
```
|
||||
|
||||
And creating a organization-owned API key:
|
||||
|
||||
```ts
|
||||
import { auth } from "@/lib/auth";
|
||||
|
||||
const apiKey = await auth.api.createApiKey({
|
||||
body: { organizationId: "org_123" },
|
||||
});
|
||||
```
|
||||
|
||||
#### Multiple configurations for API Keys
|
||||
|
||||
You can now support multiple api-key use-cases within your app!
|
||||
|
||||
```ts
|
||||
export const auth = betterAuth({
|
||||
plugins: [
|
||||
apiKey([
|
||||
{
|
||||
configId: "user-keys",
|
||||
prefix: "usr_"
|
||||
},
|
||||
{
|
||||
configId: "org-keys",
|
||||
prefix: "org_",
|
||||
references: "organization"
|
||||
}
|
||||
])
|
||||
]
|
||||
});
|
||||
```
|
||||
|
||||
To create an API Key for a given configuration, call:
|
||||
|
||||
```ts
|
||||
const key = auth.api.createApiKey({
|
||||
body: {
|
||||
configId: "user-keys",
|
||||
//...
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
---
|
||||
|
||||
### Unified Before & After Hooks
|
||||
@@ -682,6 +763,10 @@ export const auth = betterAuth({
|
||||
+ const configId = apiKey.configId;
|
||||
```
|
||||
|
||||
**Permission changes:**
|
||||
The `updateApiKey` endpoint now requires at least a `userId` parameter or headers to be passed on the server side.
|
||||
If you didn't provide this in previous version, you're now required to pass them.
|
||||
|
||||
---
|
||||
|
||||
## 🛠 Developer Changes
|
||||
|
||||
Reference in New Issue
Block a user