a83d6b83 days ago42 lines · 1.4 KB| 1 | import { createAuthPlugin |
| 2 | import { |
| 3 | type ApiKeyPluginOptions, |
| 4 | apiKeyPlugin as coreApiKeyPlugin, |
| 5 | } from "@better-auth-ui/core/plugins/api-key"; |
| 6 |
| 7 | import { OrganizationApiKeys } from "@/components/auth/api-key/organization-api-keys"; |
| 8 |
| 9 | /** Ghost calls these personal access tokens - they authenticate git over HTTP. */ |
| 10 | const patLocalization: ApiKeyPluginOptions["localization"] = { |
| 11 | apiKey: "Personal access token", |
| 12 | apiKeys: "Personal access tokens", |
| 13 | apiKeysDescription: |
| 14 | "Create a personal access token to push and pull repositories over HTTP.", |
| 15 | createApiKey: "Create token", |
| 16 | noApiKeys: "No personal access tokens", |
| 17 | newApiKey: "New personal access token", |
| 18 | newApiKeyWarning: |
| 19 | "This is the only time you'll see this token. Copy and store it somewhere safe.", |
| 20 | deleteApiKey: "Delete token", |
| 21 | deleteApiKeyWarning: |
| 22 | "This action cannot be undone. Any clone using this token will stop working immediately.", |
| 23 | dismissNewKey: "I've saved my token", |
| 24 | editApiKey: "Edit token", |
| 25 | }; |
| 26 |
| 27 | export const apiKeyPlugin = createAuthPlugin( |
| 28 | coreApiKeyPlugin.id, |
| 29 | (options: ApiKeyPluginOptions = {}) => { |
| 30 | const core = coreApiKeyPlugin({ |
| 31 | ...options, |
| 32 | localization: { ...patLocalization, ...options.localization }, |
| 33 | }); |
| 34 |
| 35 | return { |
| 36 | ...core, |
| 37 | ...(core.organization |
| 38 | ? { organizationCards: [OrganizationApiKeys] } |
| 39 | : {}), |
| 40 | }; |
| 41 | }, |
| 42 | ); |