diff --git a/docs/content/blogs/1-5.mdx b/docs/content/blogs/1-5.mdx index b29ae70ae6..d6778030f7 100644 --- a/docs/content/blogs/1-5.mdx +++ b/docs/content/blogs/1-5.mdx @@ -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