better-auth-ui 3.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +53 -0
- package/dist/auth-hooks-IOEvlYYv.d.cts +6966 -0
- package/dist/auth-hooks-IOEvlYYv.d.ts +6966 -0
- package/dist/auth-mutators-DdqOmQ32.d.cts +29 -0
- package/dist/auth-mutators-DdqOmQ32.d.ts +29 -0
- package/dist/auth-ui-provider-BsH3xJDw.d.ts +697 -0
- package/dist/auth-ui-provider-DhZfncd3.d.cts +697 -0
- package/dist/chunk-BDFQSFBU.js +750 -0
- package/dist/chunk-CRAHKL2C.cjs +801 -0
- package/dist/chunk-MJPOA6PK.js +801 -0
- package/dist/chunk-SV64DXGW.cjs +750 -0
- package/dist/index.cjs +12618 -0
- package/dist/index.d.cts +771 -0
- package/dist/index.d.ts +771 -0
- package/dist/index.js +12618 -0
- package/dist/instantdb.cjs +189 -0
- package/dist/instantdb.d.cts +36 -0
- package/dist/instantdb.d.ts +36 -0
- package/dist/instantdb.js +189 -0
- package/dist/metafile-cjs.json +1 -0
- package/dist/metafile-esm.json +1 -0
- package/dist/server.cjs +194 -0
- package/dist/server.d.cts +35 -0
- package/dist/server.d.ts +35 -0
- package/dist/server.js +194 -0
- package/dist/style.css +1 -0
- package/dist/tanstack.cjs +153 -0
- package/dist/tanstack.d.cts +18 -0
- package/dist/tanstack.d.ts +18 -0
- package/dist/tanstack.js +153 -0
- package/dist/triplit.cjs +201 -0
- package/dist/triplit.d.cts +31 -0
- package/dist/triplit.d.ts +31 -0
- package/dist/triplit.js +201 -0
- package/dist/utils-C5R37WDe.d.cts +3 -0
- package/dist/utils-C5R37WDe.d.ts +3 -0
- package/dist/view-paths-CHSJf5dv.d.cts +645 -0
- package/dist/view-paths-CHSJf5dv.d.ts +645 -0
- package/package.json +156 -0
- package/src/components/account/account-view.tsx +220 -0
- package/src/components/auth/auth-callback.tsx +36 -0
- package/src/components/auth/auth-form.tsx +277 -0
- package/src/components/auth/auth-view.tsx +389 -0
- package/src/components/auth/email-otp-button.tsx +53 -0
- package/src/components/auth/forms/email-otp-form.tsx +288 -0
- package/src/components/auth/forms/forgot-password-form.tsx +168 -0
- package/src/components/auth/forms/magic-link-form.tsx +191 -0
- package/src/components/auth/forms/recover-account-form.tsx +138 -0
- package/src/components/auth/forms/reset-password-form.tsx +215 -0
- package/src/components/auth/forms/sign-in-form.tsx +289 -0
- package/src/components/auth/forms/sign-up-form.tsx +788 -0
- package/src/components/auth/forms/two-factor-form.tsx +372 -0
- package/src/components/auth/magic-link-button.tsx +54 -0
- package/src/components/auth/one-tap.tsx +48 -0
- package/src/components/auth/otp-input-group.tsx +65 -0
- package/src/components/auth/passkey-button.tsx +85 -0
- package/src/components/auth/provider-button.tsx +141 -0
- package/src/components/auth/sign-out.tsx +25 -0
- package/src/components/auth-loading.tsx +21 -0
- package/src/components/captcha/captcha.tsx +79 -0
- package/src/components/captcha/recaptcha-badge.tsx +61 -0
- package/src/components/captcha/recaptcha-v2.tsx +58 -0
- package/src/components/captcha/recaptcha-v3.tsx +73 -0
- package/src/components/email/email-template.tsx +216 -0
- package/src/components/form-error.tsx +27 -0
- package/src/components/organization/accept-invitation-card.tsx +362 -0
- package/src/components/organization/create-organization-dialog.tsx +395 -0
- package/src/components/organization/delete-organization-card.tsx +101 -0
- package/src/components/organization/delete-organization-dialog.tsx +209 -0
- package/src/components/organization/invitation-cell.tsx +156 -0
- package/src/components/organization/invite-member-dialog.tsx +258 -0
- package/src/components/organization/leave-organization-dialog.tsx +150 -0
- package/src/components/organization/member-cell.tsx +187 -0
- package/src/components/organization/organization-cell-view.tsx +122 -0
- package/src/components/organization/organization-cell.tsx +154 -0
- package/src/components/organization/organization-invitations-card.tsx +94 -0
- package/src/components/organization/organization-logo-card.tsx +308 -0
- package/src/components/organization/organization-logo.tsx +120 -0
- package/src/components/organization/organization-members-card.tsx +155 -0
- package/src/components/organization/organization-name-card.tsx +204 -0
- package/src/components/organization/organization-settings-cards.tsx +67 -0
- package/src/components/organization/organization-slug-card.tsx +223 -0
- package/src/components/organization/organization-switcher.tsx +512 -0
- package/src/components/organization/organization-view.tsx +228 -0
- package/src/components/organization/organizations-card.tsx +72 -0
- package/src/components/organization/personal-account-view.tsx +115 -0
- package/src/components/organization/remove-member-dialog.tsx +144 -0
- package/src/components/organization/update-member-role-dialog.tsx +213 -0
- package/src/components/organization/user-invitations-card.tsx +238 -0
- package/src/components/password-input.tsx +56 -0
- package/src/components/provider-icons.tsx +385 -0
- package/src/components/redirect-to-sign-in.tsx +16 -0
- package/src/components/redirect-to-sign-up.tsx +16 -0
- package/src/components/settings/account/account-cell.tsx +158 -0
- package/src/components/settings/account/accounts-card.tsx +75 -0
- package/src/components/settings/account/delete-account-card.tsx +65 -0
- package/src/components/settings/account/delete-account-dialog.tsx +231 -0
- package/src/components/settings/account/update-avatar-card.tsx +198 -0
- package/src/components/settings/account/update-field-card.tsx +282 -0
- package/src/components/settings/account/update-name-card.tsx +39 -0
- package/src/components/settings/account/update-username-card.tsx +42 -0
- package/src/components/settings/account-settings-cards.tsx +123 -0
- package/src/components/settings/api-key/api-key-cell.tsx +108 -0
- package/src/components/settings/api-key/api-key-delete-dialog.tsx +162 -0
- package/src/components/settings/api-key/api-key-display-dialog.tsx +110 -0
- package/src/components/settings/api-key/api-keys-card.tsx +98 -0
- package/src/components/settings/api-key/create-api-key-dialog.tsx +376 -0
- package/src/components/settings/passkey/passkey-cell.tsx +113 -0
- package/src/components/settings/passkey/passkeys-card.tsx +111 -0
- package/src/components/settings/providers/provider-cell.tsx +152 -0
- package/src/components/settings/providers/providers-card.tsx +108 -0
- package/src/components/settings/security/change-email-card.tsx +200 -0
- package/src/components/settings/security/change-password-card.tsx +326 -0
- package/src/components/settings/security/session-cell.tsx +120 -0
- package/src/components/settings/security/sessions-card.tsx +58 -0
- package/src/components/settings/security-settings-cards.tsx +111 -0
- package/src/components/settings/shared/session-freshness-dialog.tsx +97 -0
- package/src/components/settings/shared/settings-action-button.tsx +51 -0
- package/src/components/settings/shared/settings-card-footer.tsx +94 -0
- package/src/components/settings/shared/settings-card-header.tsx +67 -0
- package/src/components/settings/shared/settings-card.tsx +106 -0
- package/src/components/settings/skeletons/input-field-skeleton.tsx +18 -0
- package/src/components/settings/skeletons/settings-cell-skeleton.tsx +37 -0
- package/src/components/settings/two-factor/backup-codes-dialog.tsx +113 -0
- package/src/components/settings/two-factor/two-factor-card.tsx +63 -0
- package/src/components/settings/two-factor/two-factor-password-dialog.tsx +226 -0
- package/src/components/signed-in.tsx +20 -0
- package/src/components/signed-out.tsx +20 -0
- package/src/components/ui/alert.tsx +66 -0
- package/src/components/ui/avatar.tsx +53 -0
- package/src/components/ui/button.tsx +59 -0
- package/src/components/ui/card.tsx +92 -0
- package/src/components/ui/checkbox.tsx +32 -0
- package/src/components/ui/dialog.tsx +143 -0
- package/src/components/ui/drawer.tsx +135 -0
- package/src/components/ui/dropdown-menu.tsx +257 -0
- package/src/components/ui/form.tsx +167 -0
- package/src/components/ui/input-otp.tsx +77 -0
- package/src/components/ui/input.tsx +21 -0
- package/src/components/ui/label.tsx +24 -0
- package/src/components/ui/select.tsx +185 -0
- package/src/components/ui/separator.tsx +28 -0
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/components/ui/tabs.tsx +66 -0
- package/src/components/ui/textarea.tsx +18 -0
- package/src/components/user-avatar.tsx +147 -0
- package/src/components/user-button.tsx +409 -0
- package/src/components/user-view.tsx +138 -0
- package/src/hooks/use-auth-data.ts +184 -0
- package/src/hooks/use-authenticate.ts +62 -0
- package/src/hooks/use-captcha.tsx +138 -0
- package/src/hooks/use-current-organization.ts +59 -0
- package/src/hooks/use-hydrated.ts +13 -0
- package/src/hooks/use-lang.ts +32 -0
- package/src/hooks/use-success-transition.ts +51 -0
- package/src/hooks/use-theme.ts +39 -0
- package/src/index.ts +65 -0
- package/src/instantdb.ts +1 -0
- package/src/lib/auth-data-cache.ts +90 -0
- package/src/lib/auth-ui-provider.tsx +658 -0
- package/src/lib/gravatar-utils.ts +58 -0
- package/src/lib/image-utils.ts +55 -0
- package/src/lib/instantdb/model-names.ts +24 -0
- package/src/lib/instantdb/use-instant-options.ts +98 -0
- package/src/lib/instantdb/use-list-accounts.ts +38 -0
- package/src/lib/instantdb/use-list-sessions.ts +53 -0
- package/src/lib/instantdb/use-session.ts +55 -0
- package/src/lib/organization-refetcher.tsx +56 -0
- package/src/lib/social-providers.ts +144 -0
- package/src/lib/tanstack/auth-ui-provider-tanstack.tsx +49 -0
- package/src/lib/tanstack/use-tanstack-options.ts +112 -0
- package/src/lib/triplit/model-names.ts +24 -0
- package/src/lib/triplit/use-conditional-query.ts +82 -0
- package/src/lib/triplit/use-list-accounts.ts +31 -0
- package/src/lib/triplit/use-list-sessions.ts +33 -0
- package/src/lib/triplit/use-session.ts +42 -0
- package/src/lib/triplit/use-triplit-hooks.ts +68 -0
- package/src/lib/triplit/use-triplit-token.ts +44 -0
- package/src/lib/utils.ts +105 -0
- package/src/lib/view-paths.ts +55 -0
- package/src/localization/admin-error-codes.ts +20 -0
- package/src/localization/anonymous-error-codes.ts +6 -0
- package/src/localization/api-key-error-codes.ts +32 -0
- package/src/localization/auth-localization.ts +740 -0
- package/src/localization/base-error-codes.ts +27 -0
- package/src/localization/captcha-error-codes.ts +17 -0
- package/src/localization/email-otp-error-codes.ts +7 -0
- package/src/localization/generic-oauth-error-codes.ts +3 -0
- package/src/localization/haveibeenpwned-error-codes.ts +4 -0
- package/src/localization/multi-session-error-codes.ts +3 -0
- package/src/localization/organization-error-codes.ts +57 -0
- package/src/localization/passkey-error-codes.ts +10 -0
- package/src/localization/phone-number-error-codes.ts +10 -0
- package/src/localization/stripe-localization.ts +12 -0
- package/src/localization/two-factor-error-codes.ts +12 -0
- package/src/localization/username-error-codes.ts +9 -0
- package/src/server.ts +4 -0
- package/src/style.css +1 -0
- package/src/tanstack.ts +1 -0
- package/src/triplit.ts +1 -0
- package/src/types/account-options.ts +35 -0
- package/src/types/additional-fields.ts +21 -0
- package/src/types/any-auth-client.ts +6 -0
- package/src/types/api-key.ts +9 -0
- package/src/types/auth-client.ts +37 -0
- package/src/types/auth-hooks.ts +61 -0
- package/src/types/auth-mutators.ts +17 -0
- package/src/types/avatar-options.ts +29 -0
- package/src/types/captcha-options.ts +32 -0
- package/src/types/captcha-provider.ts +6 -0
- package/src/types/credentials-options.ts +32 -0
- package/src/types/delete-user-options.ts +7 -0
- package/src/types/fetch-error.ts +6 -0
- package/src/types/generic-oauth-options.ts +16 -0
- package/src/types/gravatar-options.ts +21 -0
- package/src/types/image.ts +7 -0
- package/src/types/invitation.ts +10 -0
- package/src/types/link.ts +7 -0
- package/src/types/organization-options.ts +106 -0
- package/src/types/password-validation.ts +16 -0
- package/src/types/profile.ts +15 -0
- package/src/types/refetch.ts +1 -0
- package/src/types/render-toast.ts +9 -0
- package/src/types/sign-up-options.ts +7 -0
- package/src/types/social-options.ts +16 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { KeyRoundIcon, Loader2 } from "lucide-react"
|
|
4
|
+
import { type ComponentProps, useContext, useState } from "react"
|
|
5
|
+
|
|
6
|
+
import { useLang } from "../../../hooks/use-lang"
|
|
7
|
+
import { AuthUIContext } from "../../../lib/auth-ui-provider"
|
|
8
|
+
import { cn, getLocalizedError } from "../../../lib/utils"
|
|
9
|
+
import type { AuthLocalization } from "../../../localization/auth-localization"
|
|
10
|
+
import type { ApiKey } from "../../../types/api-key"
|
|
11
|
+
import type { Refetch } from "../../../types/refetch"
|
|
12
|
+
import { Button } from "../../ui/button"
|
|
13
|
+
import { Card } from "../../ui/card"
|
|
14
|
+
import {
|
|
15
|
+
Dialog,
|
|
16
|
+
DialogContent,
|
|
17
|
+
DialogDescription,
|
|
18
|
+
DialogFooter,
|
|
19
|
+
DialogHeader,
|
|
20
|
+
DialogTitle
|
|
21
|
+
} from "../../ui/dialog"
|
|
22
|
+
import type { SettingsCardClassNames } from "../shared/settings-card"
|
|
23
|
+
|
|
24
|
+
interface ApiKeyDeleteDialogProps extends ComponentProps<typeof Dialog> {
|
|
25
|
+
classNames?: SettingsCardClassNames
|
|
26
|
+
apiKey: ApiKey
|
|
27
|
+
localization?: AuthLocalization
|
|
28
|
+
refetch?: Refetch
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function ApiKeyDeleteDialog({
|
|
32
|
+
classNames,
|
|
33
|
+
apiKey,
|
|
34
|
+
localization,
|
|
35
|
+
refetch,
|
|
36
|
+
onOpenChange,
|
|
37
|
+
...props
|
|
38
|
+
}: ApiKeyDeleteDialogProps) {
|
|
39
|
+
const {
|
|
40
|
+
localization: contextLocalization,
|
|
41
|
+
mutators: { deleteApiKey },
|
|
42
|
+
toast
|
|
43
|
+
} = useContext(AuthUIContext)
|
|
44
|
+
|
|
45
|
+
localization = { ...contextLocalization, ...localization }
|
|
46
|
+
|
|
47
|
+
const { lang } = useLang()
|
|
48
|
+
const [isLoading, setIsLoading] = useState(false)
|
|
49
|
+
|
|
50
|
+
const handleDelete = async () => {
|
|
51
|
+
setIsLoading(true)
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
await deleteApiKey({ keyId: apiKey.id })
|
|
55
|
+
await refetch?.()
|
|
56
|
+
onOpenChange?.(false)
|
|
57
|
+
} catch (error) {
|
|
58
|
+
toast({
|
|
59
|
+
variant: "error",
|
|
60
|
+
message: getLocalizedError({ error, localization })
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
setIsLoading(false)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Format expiration date or show "Never expires"
|
|
68
|
+
const formatExpiration = () => {
|
|
69
|
+
if (!apiKey.expiresAt) return localization.NEVER_EXPIRES
|
|
70
|
+
|
|
71
|
+
const expiresDate = new Date(apiKey.expiresAt)
|
|
72
|
+
return `${localization.EXPIRES} ${expiresDate.toLocaleDateString(
|
|
73
|
+
lang ?? "en",
|
|
74
|
+
{
|
|
75
|
+
month: "short",
|
|
76
|
+
day: "numeric",
|
|
77
|
+
year: "numeric"
|
|
78
|
+
}
|
|
79
|
+
)}`
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<Dialog onOpenChange={onOpenChange} {...props}>
|
|
84
|
+
<DialogContent
|
|
85
|
+
onOpenAutoFocus={(e) => e.preventDefault()}
|
|
86
|
+
className={classNames?.dialog?.content}
|
|
87
|
+
>
|
|
88
|
+
<DialogHeader className={classNames?.dialog?.header}>
|
|
89
|
+
<DialogTitle
|
|
90
|
+
className={cn("text-lg md:text-xl", classNames?.title)}
|
|
91
|
+
>
|
|
92
|
+
{localization.DELETE} {localization.API_KEY}
|
|
93
|
+
</DialogTitle>
|
|
94
|
+
|
|
95
|
+
<DialogDescription
|
|
96
|
+
className={cn(
|
|
97
|
+
"text-xs md:text-sm",
|
|
98
|
+
classNames?.description
|
|
99
|
+
)}
|
|
100
|
+
>
|
|
101
|
+
{localization.DELETE_API_KEY_CONFIRM}
|
|
102
|
+
</DialogDescription>
|
|
103
|
+
</DialogHeader>
|
|
104
|
+
|
|
105
|
+
<Card
|
|
106
|
+
className={cn(
|
|
107
|
+
"my-2 flex-row items-center gap-3 px-4 py-3",
|
|
108
|
+
classNames?.cell
|
|
109
|
+
)}
|
|
110
|
+
>
|
|
111
|
+
<KeyRoundIcon className={cn("size-4", classNames?.icon)} />
|
|
112
|
+
|
|
113
|
+
<div className="flex flex-col">
|
|
114
|
+
<div className="flex items-center gap-2">
|
|
115
|
+
<span className="font-semibold text-sm">
|
|
116
|
+
{apiKey.name}
|
|
117
|
+
</span>
|
|
118
|
+
|
|
119
|
+
<span className="text-muted-foreground text-sm">
|
|
120
|
+
{apiKey.start}
|
|
121
|
+
{"******"}
|
|
122
|
+
</span>
|
|
123
|
+
</div>
|
|
124
|
+
|
|
125
|
+
<div className="text-muted-foreground text-xs">
|
|
126
|
+
{formatExpiration()}
|
|
127
|
+
</div>
|
|
128
|
+
</div>
|
|
129
|
+
</Card>
|
|
130
|
+
|
|
131
|
+
<DialogFooter className={classNames?.dialog?.footer}>
|
|
132
|
+
<Button
|
|
133
|
+
type="button"
|
|
134
|
+
variant="secondary"
|
|
135
|
+
onClick={() => onOpenChange?.(false)}
|
|
136
|
+
disabled={isLoading}
|
|
137
|
+
className={cn(
|
|
138
|
+
classNames?.button,
|
|
139
|
+
classNames?.secondaryButton
|
|
140
|
+
)}
|
|
141
|
+
>
|
|
142
|
+
{localization.CANCEL}
|
|
143
|
+
</Button>
|
|
144
|
+
|
|
145
|
+
<Button
|
|
146
|
+
type="button"
|
|
147
|
+
variant="destructive"
|
|
148
|
+
onClick={handleDelete}
|
|
149
|
+
disabled={isLoading}
|
|
150
|
+
className={cn(
|
|
151
|
+
classNames?.button,
|
|
152
|
+
classNames?.destructiveButton
|
|
153
|
+
)}
|
|
154
|
+
>
|
|
155
|
+
{isLoading && <Loader2 className="animate-spin" />}
|
|
156
|
+
{localization.DELETE}
|
|
157
|
+
</Button>
|
|
158
|
+
</DialogFooter>
|
|
159
|
+
</DialogContent>
|
|
160
|
+
</Dialog>
|
|
161
|
+
)
|
|
162
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { CheckIcon, CopyIcon } from "lucide-react"
|
|
4
|
+
import { type ComponentProps, useContext, useState } from "react"
|
|
5
|
+
|
|
6
|
+
import { AuthUIContext } from "../../../lib/auth-ui-provider"
|
|
7
|
+
import { cn } from "../../../lib/utils"
|
|
8
|
+
import type { AuthLocalization } from "../../../localization/auth-localization"
|
|
9
|
+
import { Button } from "../../ui/button"
|
|
10
|
+
import {
|
|
11
|
+
Dialog,
|
|
12
|
+
DialogContent,
|
|
13
|
+
DialogDescription,
|
|
14
|
+
DialogFooter,
|
|
15
|
+
DialogHeader,
|
|
16
|
+
DialogTitle
|
|
17
|
+
} from "../../ui/dialog"
|
|
18
|
+
import type { SettingsCardClassNames } from "../shared/settings-card"
|
|
19
|
+
|
|
20
|
+
interface ApiKeyDisplayDialogProps extends ComponentProps<typeof Dialog> {
|
|
21
|
+
classNames?: SettingsCardClassNames
|
|
22
|
+
localization?: AuthLocalization
|
|
23
|
+
apiKey: string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function ApiKeyDisplayDialog({
|
|
27
|
+
classNames,
|
|
28
|
+
apiKey,
|
|
29
|
+
localization,
|
|
30
|
+
onOpenChange,
|
|
31
|
+
...props
|
|
32
|
+
}: ApiKeyDisplayDialogProps) {
|
|
33
|
+
const { localization: contextLocalization } = useContext(AuthUIContext)
|
|
34
|
+
localization = { ...contextLocalization, ...localization }
|
|
35
|
+
|
|
36
|
+
const [copied, setCopied] = useState(false)
|
|
37
|
+
|
|
38
|
+
const handleCopy = () => {
|
|
39
|
+
navigator.clipboard.writeText(apiKey)
|
|
40
|
+
setCopied(true)
|
|
41
|
+
setTimeout(() => setCopied(false), 2000)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<Dialog onOpenChange={onOpenChange} {...props}>
|
|
46
|
+
<DialogContent
|
|
47
|
+
onOpenAutoFocus={(e) => e.preventDefault()}
|
|
48
|
+
className={classNames?.dialog?.content}
|
|
49
|
+
>
|
|
50
|
+
<DialogHeader className={classNames?.dialog?.header}>
|
|
51
|
+
<DialogTitle
|
|
52
|
+
className={cn("text-lg md:text-xl", classNames?.title)}
|
|
53
|
+
>
|
|
54
|
+
{localization.API_KEY_CREATED}
|
|
55
|
+
</DialogTitle>
|
|
56
|
+
|
|
57
|
+
<DialogDescription
|
|
58
|
+
className={cn(
|
|
59
|
+
"text-xs md:text-sm",
|
|
60
|
+
classNames?.description
|
|
61
|
+
)}
|
|
62
|
+
>
|
|
63
|
+
{localization.CREATE_API_KEY_SUCCESS}
|
|
64
|
+
</DialogDescription>
|
|
65
|
+
</DialogHeader>
|
|
66
|
+
|
|
67
|
+
<div className="break-all rounded-md bg-muted p-4 font-mono text-sm">
|
|
68
|
+
{apiKey}
|
|
69
|
+
</div>
|
|
70
|
+
|
|
71
|
+
<DialogFooter className={classNames?.dialog?.footer}>
|
|
72
|
+
<Button
|
|
73
|
+
type="button"
|
|
74
|
+
variant="outline"
|
|
75
|
+
onClick={handleCopy}
|
|
76
|
+
disabled={copied}
|
|
77
|
+
className={cn(
|
|
78
|
+
classNames?.button,
|
|
79
|
+
classNames?.outlineButton
|
|
80
|
+
)}
|
|
81
|
+
>
|
|
82
|
+
{copied ? (
|
|
83
|
+
<>
|
|
84
|
+
<CheckIcon className={classNames?.icon} />
|
|
85
|
+
{localization.COPIED_TO_CLIPBOARD}
|
|
86
|
+
</>
|
|
87
|
+
) : (
|
|
88
|
+
<>
|
|
89
|
+
<CopyIcon className={classNames?.icon} />
|
|
90
|
+
{localization.COPY_TO_CLIPBOARD}
|
|
91
|
+
</>
|
|
92
|
+
)}
|
|
93
|
+
</Button>
|
|
94
|
+
|
|
95
|
+
<Button
|
|
96
|
+
type="button"
|
|
97
|
+
variant="default"
|
|
98
|
+
onClick={() => onOpenChange?.(false)}
|
|
99
|
+
className={cn(
|
|
100
|
+
classNames?.button,
|
|
101
|
+
classNames?.primaryButton
|
|
102
|
+
)}
|
|
103
|
+
>
|
|
104
|
+
{localization.DONE}
|
|
105
|
+
</Button>
|
|
106
|
+
</DialogFooter>
|
|
107
|
+
</DialogContent>
|
|
108
|
+
</Dialog>
|
|
109
|
+
)
|
|
110
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useContext, useMemo, useState } from "react"
|
|
4
|
+
import { AuthUIContext } from "../../../lib/auth-ui-provider"
|
|
5
|
+
import { cn } from "../../../lib/utils"
|
|
6
|
+
import { CardContent } from "../../ui/card"
|
|
7
|
+
import type { SettingsCardProps } from "../shared/settings-card"
|
|
8
|
+
import { SettingsCard } from "../shared/settings-card"
|
|
9
|
+
import { ApiKeyCell } from "./api-key-cell"
|
|
10
|
+
import { ApiKeyDisplayDialog } from "./api-key-display-dialog"
|
|
11
|
+
import { CreateApiKeyDialog } from "./create-api-key-dialog"
|
|
12
|
+
|
|
13
|
+
export interface ApiKeysCardProps extends SettingsCardProps {
|
|
14
|
+
organizationId?: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function ApiKeysCard({
|
|
18
|
+
className,
|
|
19
|
+
classNames,
|
|
20
|
+
localization,
|
|
21
|
+
organizationId,
|
|
22
|
+
...props
|
|
23
|
+
}: ApiKeysCardProps) {
|
|
24
|
+
const {
|
|
25
|
+
hooks: { useListApiKeys },
|
|
26
|
+
localization: contextLocalization
|
|
27
|
+
} = useContext(AuthUIContext)
|
|
28
|
+
|
|
29
|
+
localization = { ...contextLocalization, ...localization }
|
|
30
|
+
|
|
31
|
+
const { data: apiKeys, isPending, refetch } = useListApiKeys()
|
|
32
|
+
|
|
33
|
+
// Filter API keys by organizationId
|
|
34
|
+
const filteredApiKeys = useMemo(() => {
|
|
35
|
+
return apiKeys?.filter(
|
|
36
|
+
(apiKey) => organizationId === apiKey.metadata?.organizationId
|
|
37
|
+
)
|
|
38
|
+
}, [apiKeys, organizationId])
|
|
39
|
+
|
|
40
|
+
const [createDialogOpen, setCreateDialogOpen] = useState(false)
|
|
41
|
+
const [displayDialogOpen, setDisplayDialogOpen] = useState(false)
|
|
42
|
+
const [createdApiKey, setCreatedApiKey] = useState("")
|
|
43
|
+
|
|
44
|
+
const handleCreateApiKey = (apiKey: string) => {
|
|
45
|
+
setCreatedApiKey(apiKey)
|
|
46
|
+
setDisplayDialogOpen(true)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<>
|
|
51
|
+
<SettingsCard
|
|
52
|
+
className={className}
|
|
53
|
+
classNames={classNames}
|
|
54
|
+
actionLabel={localization.CREATE_API_KEY}
|
|
55
|
+
description={localization.API_KEYS_DESCRIPTION}
|
|
56
|
+
instructions={localization.API_KEYS_INSTRUCTIONS}
|
|
57
|
+
isPending={isPending}
|
|
58
|
+
title={localization.API_KEYS}
|
|
59
|
+
action={() => setCreateDialogOpen(true)}
|
|
60
|
+
{...props}
|
|
61
|
+
>
|
|
62
|
+
{filteredApiKeys && filteredApiKeys.length > 0 && (
|
|
63
|
+
<CardContent
|
|
64
|
+
className={cn("grid gap-4", classNames?.content)}
|
|
65
|
+
>
|
|
66
|
+
{filteredApiKeys?.map((apiKey) => (
|
|
67
|
+
<ApiKeyCell
|
|
68
|
+
key={apiKey.id}
|
|
69
|
+
classNames={classNames}
|
|
70
|
+
apiKey={apiKey}
|
|
71
|
+
localization={localization}
|
|
72
|
+
refetch={refetch}
|
|
73
|
+
/>
|
|
74
|
+
))}
|
|
75
|
+
</CardContent>
|
|
76
|
+
)}
|
|
77
|
+
</SettingsCard>
|
|
78
|
+
|
|
79
|
+
<CreateApiKeyDialog
|
|
80
|
+
classNames={classNames}
|
|
81
|
+
localization={localization}
|
|
82
|
+
open={createDialogOpen}
|
|
83
|
+
onOpenChange={setCreateDialogOpen}
|
|
84
|
+
onSuccess={handleCreateApiKey}
|
|
85
|
+
refetch={refetch}
|
|
86
|
+
organizationId={organizationId}
|
|
87
|
+
/>
|
|
88
|
+
|
|
89
|
+
<ApiKeyDisplayDialog
|
|
90
|
+
classNames={classNames}
|
|
91
|
+
apiKey={createdApiKey}
|
|
92
|
+
localization={localization}
|
|
93
|
+
open={displayDialogOpen}
|
|
94
|
+
onOpenChange={setDisplayDialogOpen}
|
|
95
|
+
/>
|
|
96
|
+
</>
|
|
97
|
+
)
|
|
98
|
+
}
|