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.
Files changed (226) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +53 -0
  3. package/dist/auth-hooks-IOEvlYYv.d.cts +6966 -0
  4. package/dist/auth-hooks-IOEvlYYv.d.ts +6966 -0
  5. package/dist/auth-mutators-DdqOmQ32.d.cts +29 -0
  6. package/dist/auth-mutators-DdqOmQ32.d.ts +29 -0
  7. package/dist/auth-ui-provider-BsH3xJDw.d.ts +697 -0
  8. package/dist/auth-ui-provider-DhZfncd3.d.cts +697 -0
  9. package/dist/chunk-BDFQSFBU.js +750 -0
  10. package/dist/chunk-CRAHKL2C.cjs +801 -0
  11. package/dist/chunk-MJPOA6PK.js +801 -0
  12. package/dist/chunk-SV64DXGW.cjs +750 -0
  13. package/dist/index.cjs +12618 -0
  14. package/dist/index.d.cts +771 -0
  15. package/dist/index.d.ts +771 -0
  16. package/dist/index.js +12618 -0
  17. package/dist/instantdb.cjs +189 -0
  18. package/dist/instantdb.d.cts +36 -0
  19. package/dist/instantdb.d.ts +36 -0
  20. package/dist/instantdb.js +189 -0
  21. package/dist/metafile-cjs.json +1 -0
  22. package/dist/metafile-esm.json +1 -0
  23. package/dist/server.cjs +194 -0
  24. package/dist/server.d.cts +35 -0
  25. package/dist/server.d.ts +35 -0
  26. package/dist/server.js +194 -0
  27. package/dist/style.css +1 -0
  28. package/dist/tanstack.cjs +153 -0
  29. package/dist/tanstack.d.cts +18 -0
  30. package/dist/tanstack.d.ts +18 -0
  31. package/dist/tanstack.js +153 -0
  32. package/dist/triplit.cjs +201 -0
  33. package/dist/triplit.d.cts +31 -0
  34. package/dist/triplit.d.ts +31 -0
  35. package/dist/triplit.js +201 -0
  36. package/dist/utils-C5R37WDe.d.cts +3 -0
  37. package/dist/utils-C5R37WDe.d.ts +3 -0
  38. package/dist/view-paths-CHSJf5dv.d.cts +645 -0
  39. package/dist/view-paths-CHSJf5dv.d.ts +645 -0
  40. package/package.json +156 -0
  41. package/src/components/account/account-view.tsx +220 -0
  42. package/src/components/auth/auth-callback.tsx +36 -0
  43. package/src/components/auth/auth-form.tsx +277 -0
  44. package/src/components/auth/auth-view.tsx +389 -0
  45. package/src/components/auth/email-otp-button.tsx +53 -0
  46. package/src/components/auth/forms/email-otp-form.tsx +288 -0
  47. package/src/components/auth/forms/forgot-password-form.tsx +168 -0
  48. package/src/components/auth/forms/magic-link-form.tsx +191 -0
  49. package/src/components/auth/forms/recover-account-form.tsx +138 -0
  50. package/src/components/auth/forms/reset-password-form.tsx +215 -0
  51. package/src/components/auth/forms/sign-in-form.tsx +289 -0
  52. package/src/components/auth/forms/sign-up-form.tsx +788 -0
  53. package/src/components/auth/forms/two-factor-form.tsx +372 -0
  54. package/src/components/auth/magic-link-button.tsx +54 -0
  55. package/src/components/auth/one-tap.tsx +48 -0
  56. package/src/components/auth/otp-input-group.tsx +65 -0
  57. package/src/components/auth/passkey-button.tsx +85 -0
  58. package/src/components/auth/provider-button.tsx +141 -0
  59. package/src/components/auth/sign-out.tsx +25 -0
  60. package/src/components/auth-loading.tsx +21 -0
  61. package/src/components/captcha/captcha.tsx +79 -0
  62. package/src/components/captcha/recaptcha-badge.tsx +61 -0
  63. package/src/components/captcha/recaptcha-v2.tsx +58 -0
  64. package/src/components/captcha/recaptcha-v3.tsx +73 -0
  65. package/src/components/email/email-template.tsx +216 -0
  66. package/src/components/form-error.tsx +27 -0
  67. package/src/components/organization/accept-invitation-card.tsx +362 -0
  68. package/src/components/organization/create-organization-dialog.tsx +395 -0
  69. package/src/components/organization/delete-organization-card.tsx +101 -0
  70. package/src/components/organization/delete-organization-dialog.tsx +209 -0
  71. package/src/components/organization/invitation-cell.tsx +156 -0
  72. package/src/components/organization/invite-member-dialog.tsx +258 -0
  73. package/src/components/organization/leave-organization-dialog.tsx +150 -0
  74. package/src/components/organization/member-cell.tsx +187 -0
  75. package/src/components/organization/organization-cell-view.tsx +122 -0
  76. package/src/components/organization/organization-cell.tsx +154 -0
  77. package/src/components/organization/organization-invitations-card.tsx +94 -0
  78. package/src/components/organization/organization-logo-card.tsx +308 -0
  79. package/src/components/organization/organization-logo.tsx +120 -0
  80. package/src/components/organization/organization-members-card.tsx +155 -0
  81. package/src/components/organization/organization-name-card.tsx +204 -0
  82. package/src/components/organization/organization-settings-cards.tsx +67 -0
  83. package/src/components/organization/organization-slug-card.tsx +223 -0
  84. package/src/components/organization/organization-switcher.tsx +512 -0
  85. package/src/components/organization/organization-view.tsx +228 -0
  86. package/src/components/organization/organizations-card.tsx +72 -0
  87. package/src/components/organization/personal-account-view.tsx +115 -0
  88. package/src/components/organization/remove-member-dialog.tsx +144 -0
  89. package/src/components/organization/update-member-role-dialog.tsx +213 -0
  90. package/src/components/organization/user-invitations-card.tsx +238 -0
  91. package/src/components/password-input.tsx +56 -0
  92. package/src/components/provider-icons.tsx +385 -0
  93. package/src/components/redirect-to-sign-in.tsx +16 -0
  94. package/src/components/redirect-to-sign-up.tsx +16 -0
  95. package/src/components/settings/account/account-cell.tsx +158 -0
  96. package/src/components/settings/account/accounts-card.tsx +75 -0
  97. package/src/components/settings/account/delete-account-card.tsx +65 -0
  98. package/src/components/settings/account/delete-account-dialog.tsx +231 -0
  99. package/src/components/settings/account/update-avatar-card.tsx +198 -0
  100. package/src/components/settings/account/update-field-card.tsx +282 -0
  101. package/src/components/settings/account/update-name-card.tsx +39 -0
  102. package/src/components/settings/account/update-username-card.tsx +42 -0
  103. package/src/components/settings/account-settings-cards.tsx +123 -0
  104. package/src/components/settings/api-key/api-key-cell.tsx +108 -0
  105. package/src/components/settings/api-key/api-key-delete-dialog.tsx +162 -0
  106. package/src/components/settings/api-key/api-key-display-dialog.tsx +110 -0
  107. package/src/components/settings/api-key/api-keys-card.tsx +98 -0
  108. package/src/components/settings/api-key/create-api-key-dialog.tsx +376 -0
  109. package/src/components/settings/passkey/passkey-cell.tsx +113 -0
  110. package/src/components/settings/passkey/passkeys-card.tsx +111 -0
  111. package/src/components/settings/providers/provider-cell.tsx +152 -0
  112. package/src/components/settings/providers/providers-card.tsx +108 -0
  113. package/src/components/settings/security/change-email-card.tsx +200 -0
  114. package/src/components/settings/security/change-password-card.tsx +326 -0
  115. package/src/components/settings/security/session-cell.tsx +120 -0
  116. package/src/components/settings/security/sessions-card.tsx +58 -0
  117. package/src/components/settings/security-settings-cards.tsx +111 -0
  118. package/src/components/settings/shared/session-freshness-dialog.tsx +97 -0
  119. package/src/components/settings/shared/settings-action-button.tsx +51 -0
  120. package/src/components/settings/shared/settings-card-footer.tsx +94 -0
  121. package/src/components/settings/shared/settings-card-header.tsx +67 -0
  122. package/src/components/settings/shared/settings-card.tsx +106 -0
  123. package/src/components/settings/skeletons/input-field-skeleton.tsx +18 -0
  124. package/src/components/settings/skeletons/settings-cell-skeleton.tsx +37 -0
  125. package/src/components/settings/two-factor/backup-codes-dialog.tsx +113 -0
  126. package/src/components/settings/two-factor/two-factor-card.tsx +63 -0
  127. package/src/components/settings/two-factor/two-factor-password-dialog.tsx +226 -0
  128. package/src/components/signed-in.tsx +20 -0
  129. package/src/components/signed-out.tsx +20 -0
  130. package/src/components/ui/alert.tsx +66 -0
  131. package/src/components/ui/avatar.tsx +53 -0
  132. package/src/components/ui/button.tsx +59 -0
  133. package/src/components/ui/card.tsx +92 -0
  134. package/src/components/ui/checkbox.tsx +32 -0
  135. package/src/components/ui/dialog.tsx +143 -0
  136. package/src/components/ui/drawer.tsx +135 -0
  137. package/src/components/ui/dropdown-menu.tsx +257 -0
  138. package/src/components/ui/form.tsx +167 -0
  139. package/src/components/ui/input-otp.tsx +77 -0
  140. package/src/components/ui/input.tsx +21 -0
  141. package/src/components/ui/label.tsx +24 -0
  142. package/src/components/ui/select.tsx +185 -0
  143. package/src/components/ui/separator.tsx +28 -0
  144. package/src/components/ui/skeleton.tsx +13 -0
  145. package/src/components/ui/tabs.tsx +66 -0
  146. package/src/components/ui/textarea.tsx +18 -0
  147. package/src/components/user-avatar.tsx +147 -0
  148. package/src/components/user-button.tsx +409 -0
  149. package/src/components/user-view.tsx +138 -0
  150. package/src/hooks/use-auth-data.ts +184 -0
  151. package/src/hooks/use-authenticate.ts +62 -0
  152. package/src/hooks/use-captcha.tsx +138 -0
  153. package/src/hooks/use-current-organization.ts +59 -0
  154. package/src/hooks/use-hydrated.ts +13 -0
  155. package/src/hooks/use-lang.ts +32 -0
  156. package/src/hooks/use-success-transition.ts +51 -0
  157. package/src/hooks/use-theme.ts +39 -0
  158. package/src/index.ts +65 -0
  159. package/src/instantdb.ts +1 -0
  160. package/src/lib/auth-data-cache.ts +90 -0
  161. package/src/lib/auth-ui-provider.tsx +658 -0
  162. package/src/lib/gravatar-utils.ts +58 -0
  163. package/src/lib/image-utils.ts +55 -0
  164. package/src/lib/instantdb/model-names.ts +24 -0
  165. package/src/lib/instantdb/use-instant-options.ts +98 -0
  166. package/src/lib/instantdb/use-list-accounts.ts +38 -0
  167. package/src/lib/instantdb/use-list-sessions.ts +53 -0
  168. package/src/lib/instantdb/use-session.ts +55 -0
  169. package/src/lib/organization-refetcher.tsx +56 -0
  170. package/src/lib/social-providers.ts +144 -0
  171. package/src/lib/tanstack/auth-ui-provider-tanstack.tsx +49 -0
  172. package/src/lib/tanstack/use-tanstack-options.ts +112 -0
  173. package/src/lib/triplit/model-names.ts +24 -0
  174. package/src/lib/triplit/use-conditional-query.ts +82 -0
  175. package/src/lib/triplit/use-list-accounts.ts +31 -0
  176. package/src/lib/triplit/use-list-sessions.ts +33 -0
  177. package/src/lib/triplit/use-session.ts +42 -0
  178. package/src/lib/triplit/use-triplit-hooks.ts +68 -0
  179. package/src/lib/triplit/use-triplit-token.ts +44 -0
  180. package/src/lib/utils.ts +105 -0
  181. package/src/lib/view-paths.ts +55 -0
  182. package/src/localization/admin-error-codes.ts +20 -0
  183. package/src/localization/anonymous-error-codes.ts +6 -0
  184. package/src/localization/api-key-error-codes.ts +32 -0
  185. package/src/localization/auth-localization.ts +740 -0
  186. package/src/localization/base-error-codes.ts +27 -0
  187. package/src/localization/captcha-error-codes.ts +17 -0
  188. package/src/localization/email-otp-error-codes.ts +7 -0
  189. package/src/localization/generic-oauth-error-codes.ts +3 -0
  190. package/src/localization/haveibeenpwned-error-codes.ts +4 -0
  191. package/src/localization/multi-session-error-codes.ts +3 -0
  192. package/src/localization/organization-error-codes.ts +57 -0
  193. package/src/localization/passkey-error-codes.ts +10 -0
  194. package/src/localization/phone-number-error-codes.ts +10 -0
  195. package/src/localization/stripe-localization.ts +12 -0
  196. package/src/localization/two-factor-error-codes.ts +12 -0
  197. package/src/localization/username-error-codes.ts +9 -0
  198. package/src/server.ts +4 -0
  199. package/src/style.css +1 -0
  200. package/src/tanstack.ts +1 -0
  201. package/src/triplit.ts +1 -0
  202. package/src/types/account-options.ts +35 -0
  203. package/src/types/additional-fields.ts +21 -0
  204. package/src/types/any-auth-client.ts +6 -0
  205. package/src/types/api-key.ts +9 -0
  206. package/src/types/auth-client.ts +37 -0
  207. package/src/types/auth-hooks.ts +61 -0
  208. package/src/types/auth-mutators.ts +17 -0
  209. package/src/types/avatar-options.ts +29 -0
  210. package/src/types/captcha-options.ts +32 -0
  211. package/src/types/captcha-provider.ts +6 -0
  212. package/src/types/credentials-options.ts +32 -0
  213. package/src/types/delete-user-options.ts +7 -0
  214. package/src/types/fetch-error.ts +6 -0
  215. package/src/types/generic-oauth-options.ts +16 -0
  216. package/src/types/gravatar-options.ts +21 -0
  217. package/src/types/image.ts +7 -0
  218. package/src/types/invitation.ts +10 -0
  219. package/src/types/link.ts +7 -0
  220. package/src/types/organization-options.ts +106 -0
  221. package/src/types/password-validation.ts +16 -0
  222. package/src/types/profile.ts +15 -0
  223. package/src/types/refetch.ts +1 -0
  224. package/src/types/render-toast.ts +9 -0
  225. package/src/types/sign-up-options.ts +7 -0
  226. package/src/types/social-options.ts +16 -0
@@ -0,0 +1,282 @@
1
+ "use client"
2
+
3
+ import { zodResolver } from "@hookform/resolvers/zod"
4
+ import { type ReactNode, useContext, useMemo } from "react"
5
+ import { useForm } from "react-hook-form"
6
+ import * as z from "zod"
7
+
8
+ import { AuthUIContext } from "../../../lib/auth-ui-provider"
9
+ import { cn, getLocalizedError } from "../../../lib/utils"
10
+ import type { AuthLocalization } from "../../../localization/auth-localization"
11
+ import type { FieldType } from "../../../types/additional-fields"
12
+ import { CardContent } from "../../ui/card"
13
+ import { Checkbox } from "../../ui/checkbox"
14
+ import {
15
+ Form,
16
+ FormControl,
17
+ FormField,
18
+ FormItem,
19
+ FormLabel,
20
+ FormMessage
21
+ } from "../../ui/form"
22
+ import { Input } from "../../ui/input"
23
+ import { Skeleton } from "../../ui/skeleton"
24
+ import { Textarea } from "../../ui/textarea"
25
+ import {
26
+ SettingsCard,
27
+ type SettingsCardClassNames
28
+ } from "../shared/settings-card"
29
+
30
+ export interface UpdateFieldCardProps {
31
+ className?: string
32
+ classNames?: SettingsCardClassNames
33
+ description?: ReactNode
34
+ instructions?: ReactNode
35
+ localization?: Partial<AuthLocalization>
36
+ name: string
37
+ placeholder?: string
38
+ required?: boolean
39
+ label?: ReactNode
40
+ type?: FieldType
41
+ multiline?: boolean
42
+ value?: unknown
43
+ validate?: (value: string) => boolean | Promise<boolean>
44
+ }
45
+
46
+ export function UpdateFieldCard({
47
+ className,
48
+ classNames,
49
+ description,
50
+ instructions,
51
+ localization: localizationProp,
52
+ name,
53
+ placeholder,
54
+ required,
55
+ label,
56
+ type,
57
+ multiline,
58
+ value,
59
+ validate
60
+ }: UpdateFieldCardProps) {
61
+ const {
62
+ hooks: { useSession },
63
+ mutators: { updateUser },
64
+ localization: contextLocalization,
65
+ optimistic,
66
+ toast
67
+ } = useContext(AuthUIContext)
68
+
69
+ const localization = useMemo(
70
+ () => ({ ...contextLocalization, ...localizationProp }),
71
+ [contextLocalization, localizationProp]
72
+ )
73
+
74
+ const { isPending } = useSession()
75
+
76
+ let fieldSchema = z.unknown() as z.ZodType<unknown>
77
+
78
+ // Create the appropriate schema based on type
79
+ if (type === "number") {
80
+ fieldSchema = required
81
+ ? z.preprocess(
82
+ (val) => (!val ? undefined : Number(val)),
83
+ z.number({
84
+ message: `${label} ${localization.IS_INVALID}`
85
+ })
86
+ )
87
+ : z.coerce
88
+ .number({
89
+ message: `${label} ${localization.IS_INVALID}`
90
+ })
91
+ .optional()
92
+ } else if (type === "boolean") {
93
+ fieldSchema = required
94
+ ? z.coerce
95
+ .boolean({
96
+ message: `${label} ${localization.IS_INVALID}`
97
+ })
98
+ .refine((val) => val === true, {
99
+ message: `${label} ${localization.IS_REQUIRED}`
100
+ })
101
+ : z.coerce.boolean({
102
+ message: `${label} ${localization.IS_INVALID}`
103
+ })
104
+ } else {
105
+ fieldSchema = required
106
+ ? z.string().min(1, `${label} ${localization.IS_REQUIRED}`)
107
+ : z.string().optional()
108
+ }
109
+
110
+ const form = useForm({
111
+ resolver: zodResolver(z.object({ [name]: fieldSchema })),
112
+ values: { [name]: value || "" }
113
+ })
114
+
115
+ const { isSubmitting } = form.formState
116
+
117
+ const updateField = async (values: Record<string, unknown>) => {
118
+ await new Promise((resolve) => setTimeout(resolve))
119
+ const newValue = values[name]
120
+
121
+ if (value === newValue) {
122
+ toast({
123
+ variant: "error",
124
+ message: `${label} ${localization.IS_THE_SAME}`
125
+ })
126
+ return
127
+ }
128
+
129
+ if (
130
+ validate &&
131
+ typeof newValue === "string" &&
132
+ !(await validate(newValue))
133
+ ) {
134
+ form.setError(name, {
135
+ message: `${label} ${localization.IS_INVALID}`
136
+ })
137
+
138
+ return
139
+ }
140
+
141
+ try {
142
+ await updateUser({ [name]: newValue })
143
+
144
+ toast({
145
+ variant: "success",
146
+ message: `${label} ${localization.UPDATED_SUCCESSFULLY}`
147
+ })
148
+ } catch (error) {
149
+ toast({
150
+ variant: "error",
151
+ message: getLocalizedError({ error, localization })
152
+ })
153
+ }
154
+ }
155
+
156
+ return (
157
+ <Form {...form}>
158
+ <form onSubmit={form.handleSubmit(updateField)}>
159
+ <SettingsCard
160
+ className={className}
161
+ classNames={classNames}
162
+ description={description}
163
+ instructions={instructions}
164
+ isPending={isPending}
165
+ title={label}
166
+ actionLabel={localization.SAVE}
167
+ optimistic={optimistic}
168
+ >
169
+ <CardContent className={classNames?.content}>
170
+ {type === "boolean" ? (
171
+ <FormField
172
+ control={form.control}
173
+ name={name}
174
+ render={({ field }) => (
175
+ <FormItem className="flex">
176
+ <FormControl>
177
+ <Checkbox
178
+ checked={field.value as boolean}
179
+ onCheckedChange={field.onChange}
180
+ disabled={isSubmitting}
181
+ className={classNames?.checkbox}
182
+ />
183
+ </FormControl>
184
+
185
+ <FormLabel
186
+ className={classNames?.label}
187
+ >
188
+ {label}
189
+ </FormLabel>
190
+
191
+ <FormMessage
192
+ className={classNames?.error}
193
+ />
194
+ </FormItem>
195
+ )}
196
+ />
197
+ ) : isPending ? (
198
+ <Skeleton
199
+ className={cn(
200
+ "h-9 w-full",
201
+ classNames?.skeleton
202
+ )}
203
+ />
204
+ ) : (
205
+ <FormField
206
+ control={form.control}
207
+ name={name}
208
+ render={({ field }) => (
209
+ <FormItem>
210
+ <FormControl>
211
+ {type === "number" ? (
212
+ <Input
213
+ className={
214
+ classNames?.input
215
+ }
216
+ type="number"
217
+ placeholder={
218
+ placeholder ||
219
+ (typeof label ===
220
+ "string"
221
+ ? label
222
+ : "")
223
+ }
224
+ disabled={isSubmitting}
225
+ {...field}
226
+ value={
227
+ field.value as string
228
+ }
229
+ />
230
+ ) : multiline ? (
231
+ <Textarea
232
+ className={
233
+ classNames?.input
234
+ }
235
+ placeholder={
236
+ placeholder ||
237
+ (typeof label ===
238
+ "string"
239
+ ? label
240
+ : "")
241
+ }
242
+ disabled={isSubmitting}
243
+ {...field}
244
+ value={
245
+ field.value as string
246
+ }
247
+ />
248
+ ) : (
249
+ <Input
250
+ className={
251
+ classNames?.input
252
+ }
253
+ type="text"
254
+ placeholder={
255
+ placeholder ||
256
+ (typeof label ===
257
+ "string"
258
+ ? label
259
+ : "")
260
+ }
261
+ disabled={isSubmitting}
262
+ {...field}
263
+ value={
264
+ field.value as string
265
+ }
266
+ />
267
+ )}
268
+ </FormControl>
269
+
270
+ <FormMessage
271
+ className={classNames?.error}
272
+ />
273
+ </FormItem>
274
+ )}
275
+ />
276
+ )}
277
+ </CardContent>
278
+ </SettingsCard>
279
+ </form>
280
+ </Form>
281
+ )
282
+ }
@@ -0,0 +1,39 @@
1
+ "use client"
2
+
3
+ import { useContext } from "react"
4
+ import { AuthUIContext } from "../../../lib/auth-ui-provider"
5
+ import type { SettingsCardProps } from "../shared/settings-card"
6
+ import { UpdateFieldCard } from "./update-field-card"
7
+
8
+ export function UpdateNameCard({
9
+ className,
10
+ classNames,
11
+ localization,
12
+ ...props
13
+ }: SettingsCardProps) {
14
+ const {
15
+ hooks: { useSession },
16
+ localization: contextLocalization,
17
+ nameRequired
18
+ } = useContext(AuthUIContext)
19
+
20
+ localization = { ...contextLocalization, ...localization }
21
+
22
+ const { data: sessionData } = useSession()
23
+
24
+ return (
25
+ <UpdateFieldCard
26
+ className={className}
27
+ classNames={classNames}
28
+ value={sessionData?.user.name}
29
+ description={localization.NAME_DESCRIPTION}
30
+ name="name"
31
+ instructions={localization.NAME_INSTRUCTIONS}
32
+ label={localization.NAME}
33
+ localization={localization}
34
+ placeholder={localization.NAME_PLACEHOLDER}
35
+ required={nameRequired}
36
+ {...props}
37
+ />
38
+ )
39
+ }
@@ -0,0 +1,42 @@
1
+ "use client"
2
+
3
+ import { useContext } from "react"
4
+ import { AuthUIContext } from "../../../lib/auth-ui-provider"
5
+ import type { User } from "../../../types/auth-client"
6
+ import type { SettingsCardProps } from "../shared/settings-card"
7
+ import { UpdateFieldCard } from "./update-field-card"
8
+
9
+ export function UpdateUsernameCard({
10
+ className,
11
+ classNames,
12
+ localization,
13
+ ...props
14
+ }: SettingsCardProps) {
15
+ const {
16
+ hooks: { useSession },
17
+ localization: contextLocalization
18
+ } = useContext(AuthUIContext)
19
+
20
+ localization = { ...contextLocalization, ...localization }
21
+
22
+ const { data: sessionData } = useSession()
23
+ const value =
24
+ (sessionData?.user as User)?.displayUsername ||
25
+ (sessionData?.user as User)?.username
26
+
27
+ return (
28
+ <UpdateFieldCard
29
+ className={className}
30
+ classNames={classNames}
31
+ value={value}
32
+ description={localization.USERNAME_DESCRIPTION}
33
+ name="username"
34
+ instructions={localization.USERNAME_INSTRUCTIONS}
35
+ label={localization.USERNAME}
36
+ localization={localization}
37
+ placeholder={localization.USERNAME_PLACEHOLDER}
38
+ required
39
+ {...props}
40
+ />
41
+ )
42
+ }
@@ -0,0 +1,123 @@
1
+ "use client"
2
+
3
+ import { useContext } from "react"
4
+
5
+ import { AuthUIContext } from "../../lib/auth-ui-provider"
6
+ import { cn } from "../../lib/utils"
7
+ import type { AuthLocalization } from "../../localization/auth-localization"
8
+ import { AccountsCard } from "./account/accounts-card"
9
+ import { UpdateAvatarCard } from "./account/update-avatar-card"
10
+ import { UpdateFieldCard } from "./account/update-field-card"
11
+ import { UpdateNameCard } from "./account/update-name-card"
12
+ import { UpdateUsernameCard } from "./account/update-username-card"
13
+ import { ChangeEmailCard } from "./security/change-email-card"
14
+ import type { SettingsCardClassNames } from "./shared/settings-card"
15
+
16
+ export function AccountSettingsCards({
17
+ className,
18
+ classNames,
19
+ localization
20
+ }: {
21
+ className?: string
22
+ classNames?: {
23
+ card?: SettingsCardClassNames
24
+ cards?: string
25
+ }
26
+ localization?: Partial<AuthLocalization>
27
+ }) {
28
+ const {
29
+ additionalFields,
30
+ avatar,
31
+ changeEmail,
32
+ credentials,
33
+ hooks: { useSession },
34
+ multiSession,
35
+ account: accountOptions
36
+ } = useContext(AuthUIContext)
37
+
38
+ const { data: sessionData } = useSession()
39
+
40
+ return (
41
+ <div
42
+ className={cn(
43
+ "flex w-full flex-col gap-4 md:gap-6",
44
+ className,
45
+ classNames?.cards
46
+ )}
47
+ >
48
+ {accountOptions?.fields?.includes("image") && avatar && (
49
+ <UpdateAvatarCard
50
+ classNames={classNames?.card}
51
+ localization={localization}
52
+ />
53
+ )}
54
+
55
+ {credentials?.username && (
56
+ <UpdateUsernameCard
57
+ classNames={classNames?.card}
58
+ localization={localization}
59
+ />
60
+ )}
61
+
62
+ {accountOptions?.fields?.includes("name") && (
63
+ <UpdateNameCard
64
+ classNames={classNames?.card}
65
+ localization={localization}
66
+ />
67
+ )}
68
+
69
+ {changeEmail && (
70
+ <ChangeEmailCard
71
+ classNames={classNames?.card}
72
+ localization={localization}
73
+ />
74
+ )}
75
+
76
+ {accountOptions?.fields?.map((field) => {
77
+ if (field === "image") return null
78
+ if (field === "name") return null
79
+ const additionalField = additionalFields?.[field]
80
+ if (!additionalField) return null
81
+
82
+ const {
83
+ label,
84
+ description,
85
+ instructions,
86
+ placeholder,
87
+ required,
88
+ type,
89
+ multiline,
90
+ validate
91
+ } = additionalField
92
+
93
+ // @ts-expect-error Custom fields are not typed
94
+ const defaultValue = sessionData?.user[field] as unknown
95
+
96
+ return (
97
+ <UpdateFieldCard
98
+ key={field}
99
+ classNames={classNames?.card}
100
+ value={defaultValue}
101
+ description={description}
102
+ name={field}
103
+ instructions={instructions}
104
+ label={label}
105
+ localization={localization}
106
+ placeholder={placeholder}
107
+ required={required}
108
+ type={type}
109
+ multiline={multiline}
110
+ validate={validate}
111
+ />
112
+ )
113
+ })}
114
+
115
+ {multiSession && (
116
+ <AccountsCard
117
+ classNames={classNames?.card}
118
+ localization={localization}
119
+ />
120
+ )}
121
+ </div>
122
+ )
123
+ }
@@ -0,0 +1,108 @@
1
+ "use client"
2
+
3
+ import { KeyRoundIcon } from "lucide-react"
4
+ import { useContext, useState } from "react"
5
+
6
+ import { useLang } from "../../../hooks/use-lang"
7
+ import { AuthUIContext } from "../../../lib/auth-ui-provider"
8
+ import { cn } 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 type { SettingsCardClassNames } from "../shared/settings-card"
15
+ import { ApiKeyDeleteDialog } from "./api-key-delete-dialog"
16
+
17
+ export interface ApiKeyCellProps {
18
+ className?: string
19
+ classNames?: SettingsCardClassNames
20
+ apiKey: ApiKey
21
+ localization?: Partial<AuthLocalization>
22
+ refetch?: Refetch
23
+ }
24
+
25
+ export function ApiKeyCell({
26
+ className,
27
+ classNames,
28
+ apiKey,
29
+ localization,
30
+ refetch
31
+ }: ApiKeyCellProps) {
32
+ const { localization: contextLocalization } = useContext(AuthUIContext)
33
+ localization = { ...contextLocalization, ...localization }
34
+
35
+ const { lang } = useLang()
36
+
37
+ const [showDeleteDialog, setShowDeleteDialog] = useState(false)
38
+
39
+ // Format expiration date or show "Never expires"
40
+ const formatExpiration = () => {
41
+ if (!apiKey.expiresAt) return localization.NEVER_EXPIRES
42
+
43
+ const expiresDate = new Date(apiKey.expiresAt)
44
+ return `${localization.EXPIRES} ${expiresDate.toLocaleDateString(
45
+ lang ?? "en",
46
+ {
47
+ month: "short",
48
+ day: "numeric",
49
+ year: "numeric"
50
+ }
51
+ )}`
52
+ }
53
+
54
+ return (
55
+ <>
56
+ <Card
57
+ className={cn(
58
+ "flex-row items-center gap-3 truncate px-4 py-3",
59
+ className,
60
+ classNames?.cell
61
+ )}
62
+ >
63
+ <KeyRoundIcon
64
+ className={cn("size-4 flex-shrink-0", classNames?.icon)}
65
+ />
66
+
67
+ <div className="flex flex-col truncate">
68
+ <div className="flex items-center gap-2">
69
+ <span className="truncate font-semibold text-sm">
70
+ {apiKey.name}
71
+ </span>
72
+
73
+ <span className="flex-1 truncate text-muted-foreground text-sm">
74
+ {apiKey.start}
75
+ {"******"}
76
+ </span>
77
+ </div>
78
+
79
+ <div className="truncate text-muted-foreground text-xs">
80
+ {formatExpiration()}
81
+ </div>
82
+ </div>
83
+
84
+ <Button
85
+ className={cn(
86
+ "relative ms-auto",
87
+ classNames?.button,
88
+ classNames?.outlineButton
89
+ )}
90
+ size="sm"
91
+ variant="outline"
92
+ onClick={() => setShowDeleteDialog(true)}
93
+ >
94
+ {localization.DELETE}
95
+ </Button>
96
+ </Card>
97
+
98
+ <ApiKeyDeleteDialog
99
+ classNames={classNames}
100
+ apiKey={apiKey}
101
+ localization={localization}
102
+ open={showDeleteDialog}
103
+ onOpenChange={setShowDeleteDialog}
104
+ refetch={refetch}
105
+ />
106
+ </>
107
+ )
108
+ }