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,228 @@
1
+ "use client"
2
+
3
+ import { MenuIcon } from "lucide-react"
4
+ import { useContext, useEffect, useMemo } from "react"
5
+ import { useAuthenticate } from "../../hooks/use-authenticate"
6
+ import { useCurrentOrganization } from "../../hooks/use-current-organization"
7
+ import { AuthUIContext } from "../../lib/auth-ui-provider"
8
+ import { cn, getViewByPath } from "../../lib/utils"
9
+ import type { OrganizationViewPath } from "../../server"
10
+ import type { AccountViewProps } from "../account/account-view"
11
+ import { ApiKeysCard } from "../settings/api-key/api-keys-card"
12
+ import { Button } from "../ui/button"
13
+ import {
14
+ Drawer,
15
+ DrawerContent,
16
+ DrawerHeader,
17
+ DrawerTitle,
18
+ DrawerTrigger
19
+ } from "../ui/drawer"
20
+ import { Label } from "../ui/label"
21
+ import { OrganizationInvitationsCard } from "./organization-invitations-card"
22
+ import { OrganizationMembersCard } from "./organization-members-card"
23
+ import { OrganizationSettingsCards } from "./organization-settings-cards"
24
+
25
+ export type OrganizationViewPageProps = Omit<AccountViewProps, "view"> & {
26
+ slug?: string
27
+ view?: OrganizationViewPath
28
+ }
29
+
30
+ export function OrganizationView({
31
+ className,
32
+ classNames,
33
+ localization: localizationProp,
34
+ path: pathProp,
35
+ pathname,
36
+ view: viewProp,
37
+ hideNav,
38
+ slug: slugProp
39
+ }: OrganizationViewPageProps) {
40
+ const {
41
+ organization: organizationOptions,
42
+ localization: contextLocalization,
43
+ account: accountOptions,
44
+ Link,
45
+ replace
46
+ } = useContext(AuthUIContext)
47
+
48
+ const { slug: contextSlug, viewPaths, apiKey } = organizationOptions || {}
49
+
50
+ useAuthenticate()
51
+
52
+ const localization = useMemo(
53
+ () => ({ ...contextLocalization, ...localizationProp }),
54
+ [contextLocalization, localizationProp]
55
+ )
56
+
57
+ const path = pathProp ?? pathname?.split("/").pop()
58
+
59
+ const view = viewProp || getViewByPath(viewPaths!, path) || "SETTINGS"
60
+
61
+ const slug = slugProp || contextSlug
62
+
63
+ const {
64
+ data: organization,
65
+ isPending: organizationPending,
66
+ isRefetching: organizationRefetching
67
+ } = useCurrentOrganization({ slug })
68
+
69
+ const navItems: {
70
+ view: OrganizationViewPath
71
+ label: string
72
+ }[] = [
73
+ { view: "SETTINGS", label: localization.SETTINGS },
74
+ { view: "MEMBERS", label: localization.MEMBERS }
75
+ ]
76
+
77
+ if (apiKey) {
78
+ navItems.push({
79
+ view: "API_KEYS",
80
+ label: localization.API_KEYS
81
+ })
82
+ }
83
+
84
+ useEffect(() => {
85
+ if (organization || organizationPending || organizationRefetching)
86
+ return
87
+
88
+ replace(
89
+ `${accountOptions?.basePath}/${accountOptions?.viewPaths?.ORGANIZATIONS}`
90
+ )
91
+ }, [
92
+ organization,
93
+ organizationPending,
94
+ organizationRefetching,
95
+ accountOptions?.basePath,
96
+ accountOptions?.viewPaths?.ORGANIZATIONS,
97
+ replace
98
+ ])
99
+
100
+ return (
101
+ <div
102
+ className={cn(
103
+ "flex w-full grow flex-col gap-4 md:flex-row md:gap-12",
104
+ className,
105
+ classNames?.base
106
+ )}
107
+ >
108
+ {!hideNav && (
109
+ <div className="flex justify-between gap-2 md:hidden">
110
+ <Label className="font-semibold text-base">
111
+ {navItems.find((i) => i.view === view)?.label}
112
+ </Label>
113
+
114
+ <Drawer>
115
+ <DrawerTrigger asChild>
116
+ <Button variant="outline">
117
+ <MenuIcon />
118
+ </Button>
119
+ </DrawerTrigger>
120
+
121
+ <DrawerContent>
122
+ <DrawerHeader>
123
+ <DrawerTitle className="hidden">
124
+ {localization.ORGANIZATION}
125
+ </DrawerTitle>
126
+ </DrawerHeader>
127
+ <div className="flex flex-col px-4 pb-4">
128
+ {navItems.map((item) => (
129
+ <Link
130
+ key={item.view}
131
+ href={`${organizationOptions?.basePath}${organizationOptions?.pathMode === "slug" ? `/${slug}` : ""}/${organizationOptions?.viewPaths[item.view]}`}
132
+ >
133
+ <Button
134
+ size="lg"
135
+ className={cn(
136
+ "w-full justify-start px-4 transition-none",
137
+ classNames?.drawer?.menuItem,
138
+ view === item.view
139
+ ? "font-semibold"
140
+ : "text-foreground/70"
141
+ )}
142
+ variant="ghost"
143
+ >
144
+ {item.label}
145
+ </Button>
146
+ </Link>
147
+ ))}
148
+ </div>
149
+ </DrawerContent>
150
+ </Drawer>
151
+ </div>
152
+ )}
153
+
154
+ {!hideNav && (
155
+ <div className="hidden md:block">
156
+ <div
157
+ className={cn(
158
+ "flex w-48 flex-col gap-1 lg:w-60",
159
+ classNames?.sidebar?.base
160
+ )}
161
+ >
162
+ {navItems.map((item) => (
163
+ <Link
164
+ key={item.view}
165
+ href={`${organizationOptions?.basePath}${organizationOptions?.pathMode === "slug" ? `/${slug}` : ""}/${organizationOptions?.viewPaths[item.view]}`}
166
+ >
167
+ <Button
168
+ size="lg"
169
+ className={cn(
170
+ "w-full justify-start px-4 transition-none",
171
+ classNames?.sidebar?.button,
172
+ view === item.view
173
+ ? "font-semibold"
174
+ : "text-foreground/70",
175
+ view === item.view &&
176
+ classNames?.sidebar?.buttonActive
177
+ )}
178
+ variant="ghost"
179
+ >
180
+ {item.label}
181
+ </Button>
182
+ </Link>
183
+ ))}
184
+ </div>
185
+ </div>
186
+ )}
187
+
188
+ {view === "MEMBERS" && (
189
+ <div
190
+ className={cn(
191
+ "flex w-full flex-col gap-4 md:gap-6",
192
+ className,
193
+ classNames?.cards
194
+ )}
195
+ >
196
+ <OrganizationMembersCard
197
+ classNames={classNames?.card}
198
+ localization={localization}
199
+ slug={slug}
200
+ />
201
+
202
+ <OrganizationInvitationsCard
203
+ classNames={classNames?.card}
204
+ localization={localization}
205
+ slug={slug}
206
+ />
207
+ </div>
208
+ )}
209
+
210
+ {view === "API_KEYS" && (
211
+ <ApiKeysCard
212
+ classNames={classNames?.card}
213
+ localization={localization}
214
+ isPending={organizationPending}
215
+ organizationId={organization?.id}
216
+ />
217
+ )}
218
+
219
+ {view === "SETTINGS" && (
220
+ <OrganizationSettingsCards
221
+ classNames={classNames}
222
+ localization={localization}
223
+ slug={slug}
224
+ />
225
+ )}
226
+ </div>
227
+ )
228
+ }
@@ -0,0 +1,72 @@
1
+ "use client"
2
+ import { useContext, useMemo, useState } from "react"
3
+
4
+ import { useIsHydrated } from "../../hooks/use-hydrated"
5
+ import { AuthUIContext } from "../../lib/auth-ui-provider"
6
+ import { cn } from "../../lib/utils"
7
+ import type { SettingsCardProps } from "../settings/shared/settings-card"
8
+ import { SettingsCard } from "../settings/shared/settings-card"
9
+ import { SettingsCellSkeleton } from "../settings/skeletons/settings-cell-skeleton"
10
+ import { CardContent } from "../ui/card"
11
+ import { CreateOrganizationDialog } from "./create-organization-dialog"
12
+ import { OrganizationCell } from "./organization-cell"
13
+
14
+ export function OrganizationsCard({
15
+ className,
16
+ classNames,
17
+ localization,
18
+ ...props
19
+ }: SettingsCardProps) {
20
+ const {
21
+ hooks: { useListOrganizations },
22
+ localization: contextLocalization
23
+ } = useContext(AuthUIContext)
24
+
25
+ localization = useMemo(
26
+ () => ({ ...contextLocalization, ...localization }),
27
+ [contextLocalization, localization]
28
+ )
29
+
30
+ const isHydrated = useIsHydrated()
31
+ const { data: organizations, isPending: organizationsPending } =
32
+ useListOrganizations()
33
+
34
+ const isPending = !isHydrated || organizationsPending
35
+
36
+ const [createDialogOpen, setCreateDialogOpen] = useState(false)
37
+
38
+ return (
39
+ <>
40
+ <SettingsCard
41
+ className={className}
42
+ classNames={classNames}
43
+ title={localization.ORGANIZATIONS}
44
+ description={localization.ORGANIZATIONS_DESCRIPTION}
45
+ instructions={localization.ORGANIZATIONS_INSTRUCTIONS}
46
+ actionLabel={localization.CREATE_ORGANIZATION}
47
+ action={() => setCreateDialogOpen(true)}
48
+ isPending={isPending}
49
+ {...props}
50
+ >
51
+ <CardContent className={cn("grid gap-4", classNames?.content)}>
52
+ {isPending && <SettingsCellSkeleton />}
53
+ {organizations?.map((organization) => (
54
+ <OrganizationCell
55
+ key={organization.id}
56
+ classNames={classNames}
57
+ organization={organization}
58
+ localization={localization}
59
+ />
60
+ ))}
61
+ </CardContent>
62
+ </SettingsCard>
63
+
64
+ <CreateOrganizationDialog
65
+ classNames={classNames}
66
+ localization={localization}
67
+ open={createDialogOpen}
68
+ onOpenChange={setCreateDialogOpen}
69
+ />
70
+ </>
71
+ )
72
+ }
@@ -0,0 +1,115 @@
1
+ "use client"
2
+
3
+ import { useContext, useMemo } from "react"
4
+ import { AuthUIContext } from "../../lib/auth-ui-provider"
5
+ import { cn } from "../../lib/utils"
6
+ import { Skeleton } from "../ui/skeleton"
7
+ import { UserAvatar } from "../user-avatar"
8
+ import type { UserViewProps } from "../user-view"
9
+
10
+ /**
11
+ * Displays user information with avatar and details in a compact view for personal accounts
12
+ *
13
+ * Renders a user's profile information with appropriate fallbacks:
14
+ * - Shows avatar alongside user name and "Personal Account" subtitle when available
15
+ * - Shows loading skeletons when isPending is true
16
+ * - Falls back to generic "User" text when neither name nor email is available
17
+ * - Always shows "Personal Account" as subtitle for default and lg sizes
18
+ * - Supports customization through classNames prop
19
+ */
20
+ export function PersonalAccountView({
21
+ className,
22
+ classNames,
23
+ isPending,
24
+ size,
25
+ user,
26
+ localization: propLocalization
27
+ }: UserViewProps) {
28
+ const { localization: contextLocalization } = useContext(AuthUIContext)
29
+
30
+ const localization = useMemo(
31
+ () => ({ ...contextLocalization, ...propLocalization }),
32
+ [contextLocalization, propLocalization]
33
+ )
34
+
35
+ return (
36
+ <div
37
+ className={cn(
38
+ "flex items-center gap-2",
39
+ className,
40
+ classNames?.base
41
+ )}
42
+ >
43
+ <UserAvatar
44
+ className={cn(size !== "sm" && "my-0.5")}
45
+ classNames={classNames?.avatar}
46
+ isPending={isPending}
47
+ localization={localization}
48
+ size={size}
49
+ user={user}
50
+ />
51
+
52
+ <div
53
+ className={cn(
54
+ "grid flex-1 text-left leading-tight",
55
+ classNames?.content
56
+ )}
57
+ >
58
+ {isPending ? (
59
+ <>
60
+ <Skeleton
61
+ className={cn(
62
+ "max-w-full",
63
+ size === "lg" ? "h-4.5 w-32" : "h-3.5 w-24",
64
+ classNames?.title,
65
+ classNames?.skeleton
66
+ )}
67
+ />
68
+
69
+ {size !== "sm" && (
70
+ <Skeleton
71
+ className={cn(
72
+ "mt-1.5 max-w-full",
73
+ size === "lg" ? "h-3.5 w-40" : "h-3 w-32",
74
+ classNames?.subtitle,
75
+ classNames?.skeleton
76
+ )}
77
+ />
78
+ )}
79
+ </>
80
+ ) : (
81
+ <>
82
+ <span
83
+ className={cn(
84
+ "truncate font-semibold",
85
+ size === "lg" ? "text-base" : "text-sm",
86
+ classNames?.title
87
+ )}
88
+ >
89
+ {user?.displayName ||
90
+ user?.name ||
91
+ user?.fullName ||
92
+ user?.firstName ||
93
+ user?.displayUsername ||
94
+ user?.username ||
95
+ user?.email ||
96
+ localization?.USER}
97
+ </span>
98
+
99
+ {size !== "sm" && (
100
+ <span
101
+ className={cn(
102
+ "truncate opacity-70",
103
+ size === "lg" ? "text-sm" : "text-xs",
104
+ classNames?.subtitle
105
+ )}
106
+ >
107
+ {localization?.PERSONAL_ACCOUNT}
108
+ </span>
109
+ )}
110
+ </>
111
+ )}
112
+ </div>
113
+ </div>
114
+ )
115
+ }
@@ -0,0 +1,144 @@
1
+ "use client"
2
+
3
+ import type { User } from "better-auth"
4
+ import type { Member } from "better-auth/plugins/organization"
5
+ import { Loader2 } from "lucide-react"
6
+ import { type ComponentProps, useContext, useMemo, useState } from "react"
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 { SettingsCardClassNames } from "../settings/shared/settings-card"
12
+ import { Button } from "../ui/button"
13
+ import {
14
+ Dialog,
15
+ DialogContent,
16
+ DialogDescription,
17
+ DialogFooter,
18
+ DialogHeader,
19
+ DialogTitle
20
+ } from "../ui/dialog"
21
+ import { MemberCell } from "./member-cell"
22
+
23
+ export interface RemoveMemberDialogProps extends ComponentProps<typeof Dialog> {
24
+ classNames?: SettingsCardClassNames
25
+ localization?: AuthLocalization
26
+ member: Member & { user?: Partial<User> | null }
27
+ }
28
+
29
+ export function RemoveMemberDialog({
30
+ member,
31
+ classNames,
32
+ localization: localizationProp,
33
+ onOpenChange,
34
+ ...props
35
+ }: RemoveMemberDialogProps) {
36
+ const {
37
+ authClient,
38
+ hooks: { useListMembers },
39
+ localization: contextLocalization,
40
+ toast
41
+ } = useContext(AuthUIContext)
42
+
43
+ const localization = useMemo(
44
+ () => ({ ...contextLocalization, ...localizationProp }),
45
+ [contextLocalization, localizationProp]
46
+ )
47
+
48
+ const { refetch } = useListMembers({
49
+ query: { organizationId: member.organizationId }
50
+ })
51
+
52
+ const [isRemoving, setIsRemoving] = useState(false)
53
+
54
+ const removeMember = async () => {
55
+ setIsRemoving(true)
56
+
57
+ try {
58
+ await authClient.organization.removeMember({
59
+ memberIdOrEmail: member.id,
60
+ organizationId: member.organizationId,
61
+ fetchOptions: { throw: true }
62
+ })
63
+
64
+ toast({
65
+ variant: "success",
66
+ message: localization.REMOVE_MEMBER_SUCCESS
67
+ })
68
+
69
+ await refetch?.()
70
+
71
+ onOpenChange?.(false)
72
+ } catch (error) {
73
+ toast({
74
+ variant: "error",
75
+ message: getLocalizedError({ error, localization })
76
+ })
77
+ }
78
+
79
+ setIsRemoving(false)
80
+ }
81
+
82
+ return (
83
+ <Dialog onOpenChange={onOpenChange} {...props}>
84
+ <DialogContent
85
+ className={classNames?.dialog?.content}
86
+ onOpenAutoFocus={(e) => e.preventDefault()}
87
+ >
88
+ <DialogHeader className={classNames?.dialog?.header}>
89
+ <DialogTitle
90
+ className={cn("text-lg md:text-xl", classNames?.title)}
91
+ >
92
+ {localization.REMOVE_MEMBER}
93
+ </DialogTitle>
94
+
95
+ <DialogDescription
96
+ className={cn(
97
+ "text-xs md:text-sm",
98
+ classNames?.description
99
+ )}
100
+ >
101
+ {localization.REMOVE_MEMBER_CONFIRM}
102
+ </DialogDescription>
103
+ </DialogHeader>
104
+
105
+ <MemberCell
106
+ className={classNames?.cell}
107
+ member={member}
108
+ localization={localization}
109
+ hideActions
110
+ />
111
+
112
+ <DialogFooter className={classNames?.dialog?.footer}>
113
+ <Button
114
+ type="button"
115
+ variant="outline"
116
+ onClick={() => onOpenChange?.(false)}
117
+ className={cn(
118
+ classNames?.button,
119
+ classNames?.outlineButton
120
+ )}
121
+ disabled={isRemoving}
122
+ >
123
+ {localization.CANCEL}
124
+ </Button>
125
+
126
+ <Button
127
+ type="button"
128
+ variant="destructive"
129
+ onClick={removeMember}
130
+ className={cn(
131
+ classNames?.button,
132
+ classNames?.destructiveButton
133
+ )}
134
+ disabled={isRemoving}
135
+ >
136
+ {isRemoving && <Loader2 className="animate-spin" />}
137
+
138
+ {localization.REMOVE_MEMBER}
139
+ </Button>
140
+ </DialogFooter>
141
+ </DialogContent>
142
+ </Dialog>
143
+ )
144
+ }