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,213 @@
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
+ 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 { SettingsCardClassNames } from "../settings/shared/settings-card"
11
+ import { Button } from "../ui/button"
12
+ import {
13
+ Dialog,
14
+ DialogContent,
15
+ DialogDescription,
16
+ DialogFooter,
17
+ DialogHeader,
18
+ DialogTitle
19
+ } from "../ui/dialog"
20
+ import {
21
+ Select,
22
+ SelectContent,
23
+ SelectItem,
24
+ SelectTrigger,
25
+ SelectValue
26
+ } from "../ui/select"
27
+ import { MemberCell } from "./member-cell"
28
+
29
+ export interface UpdateMemberRoleDialogProps
30
+ extends ComponentProps<typeof Dialog> {
31
+ classNames?: SettingsCardClassNames
32
+ localization?: AuthLocalization
33
+ member: Member & { user?: Partial<User> | null }
34
+ }
35
+
36
+ export function UpdateMemberRoleDialog({
37
+ member,
38
+ classNames,
39
+ localization: localizationProp,
40
+ onOpenChange,
41
+ ...props
42
+ }: UpdateMemberRoleDialogProps) {
43
+ const {
44
+ authClient,
45
+ hooks: { useSession, useListMembers },
46
+ localization: contextLocalization,
47
+ organization,
48
+ toast
49
+ } = useContext(AuthUIContext)
50
+
51
+ const localization = useMemo(
52
+ () => ({ ...contextLocalization, ...localizationProp }),
53
+ [contextLocalization, localizationProp]
54
+ )
55
+
56
+ const { data, refetch } = useListMembers({
57
+ query: { organizationId: member.organizationId }
58
+ })
59
+
60
+ const members = data?.members
61
+
62
+ const { data: sessionData } = useSession()
63
+
64
+ const [isUpdating, setIsUpdating] = useState(false)
65
+ const [selectedRole, setSelectedRole] = useState(member.role)
66
+
67
+ const builtInRoles = [
68
+ { role: "owner", label: localization.OWNER },
69
+ { role: "admin", label: localization.ADMIN },
70
+ { role: "member", label: localization.MEMBER }
71
+ ]
72
+
73
+ const roles = [...builtInRoles, ...(organization?.customRoles || [])]
74
+
75
+ const currentUserRole = members?.find(
76
+ (m) => m.user?.id === sessionData?.user.id
77
+ )?.role
78
+
79
+ const availableRoles = roles.filter((role) => {
80
+ if (role.role === "owner") {
81
+ return currentUserRole === "owner"
82
+ }
83
+
84
+ if (role.role === "admin") {
85
+ return currentUserRole === "owner" || currentUserRole === "admin"
86
+ }
87
+
88
+ return true
89
+ })
90
+
91
+ const updateMemberRole = async () => {
92
+ if (selectedRole === member.role) {
93
+ toast({
94
+ variant: "error",
95
+ message: `${localization.ROLE} ${localization.IS_THE_SAME}`
96
+ })
97
+
98
+ return
99
+ }
100
+
101
+ setIsUpdating(true)
102
+
103
+ try {
104
+ await authClient.organization.updateMemberRole({
105
+ memberId: member.id,
106
+ role: selectedRole,
107
+ organizationId: member.organizationId,
108
+ fetchOptions: {
109
+ throw: true
110
+ }
111
+ })
112
+
113
+ toast({
114
+ variant: "success",
115
+ message: localization.MEMBER_ROLE_UPDATED
116
+ })
117
+
118
+ await refetch?.()
119
+
120
+ onOpenChange?.(false)
121
+ } catch (error) {
122
+ toast({
123
+ variant: "error",
124
+ message: getLocalizedError({ error, localization })
125
+ })
126
+ }
127
+
128
+ setIsUpdating(false)
129
+ }
130
+
131
+ return (
132
+ <Dialog onOpenChange={onOpenChange} {...props}>
133
+ <DialogContent
134
+ className={classNames?.dialog?.content}
135
+ onOpenAutoFocus={(e) => e.preventDefault()}
136
+ >
137
+ <DialogHeader className={classNames?.dialog?.header}>
138
+ <DialogTitle
139
+ className={cn("text-lg md:text-xl", classNames?.title)}
140
+ >
141
+ {localization.UPDATE_ROLE}
142
+ </DialogTitle>
143
+
144
+ <DialogDescription
145
+ className={cn(
146
+ "text-xs md:text-sm",
147
+ classNames?.description
148
+ )}
149
+ >
150
+ {localization.UPDATE_ROLE_DESCRIPTION}
151
+ </DialogDescription>
152
+ </DialogHeader>
153
+
154
+ <div className="grid gap-6 py-4">
155
+ <MemberCell
156
+ className={classNames?.cell}
157
+ member={member}
158
+ localization={localization}
159
+ hideActions
160
+ />
161
+
162
+ <Select
163
+ value={selectedRole}
164
+ onValueChange={setSelectedRole}
165
+ >
166
+ <SelectTrigger className="w-full">
167
+ <SelectValue
168
+ placeholder={localization.SELECT_ROLE}
169
+ />
170
+ </SelectTrigger>
171
+
172
+ <SelectContent>
173
+ {availableRoles.map((role) => (
174
+ <SelectItem key={role.role} value={role.role}>
175
+ {role.label}
176
+ </SelectItem>
177
+ ))}
178
+ </SelectContent>
179
+ </Select>
180
+ </div>
181
+
182
+ <DialogFooter className={classNames?.dialog?.footer}>
183
+ <Button
184
+ type="button"
185
+ variant="outline"
186
+ onClick={() => onOpenChange?.(false)}
187
+ className={cn(
188
+ classNames?.button,
189
+ classNames?.outlineButton
190
+ )}
191
+ disabled={isUpdating}
192
+ >
193
+ {localization.CANCEL}
194
+ </Button>
195
+
196
+ <Button
197
+ type="button"
198
+ onClick={updateMemberRole}
199
+ className={cn(
200
+ classNames?.button,
201
+ classNames?.primaryButton
202
+ )}
203
+ disabled={isUpdating}
204
+ >
205
+ {isUpdating && <Loader2 className="animate-spin" />}
206
+
207
+ {localization.UPDATE_ROLE}
208
+ </Button>
209
+ </DialogFooter>
210
+ </DialogContent>
211
+ </Dialog>
212
+ )
213
+ }
@@ -0,0 +1,238 @@
1
+ "use client"
2
+
3
+ import { CheckIcon, EllipsisIcon, Loader2, XIcon } from "lucide-react"
4
+ import { useContext, useMemo, useState } from "react"
5
+
6
+ import { AuthUIContext } from "../../lib/auth-ui-provider"
7
+ import { cn, getLocalizedError } from "../../lib/utils"
8
+ import type { SettingsCardProps } from "../settings/shared/settings-card"
9
+ import { SettingsCard } from "../settings/shared/settings-card"
10
+ import { Button } from "../ui/button"
11
+ import { Card, CardContent } from "../ui/card"
12
+ import {
13
+ DropdownMenu,
14
+ DropdownMenuContent,
15
+ DropdownMenuItem,
16
+ DropdownMenuTrigger
17
+ } from "../ui/dropdown-menu"
18
+ import { UserAvatar } from "../user-avatar"
19
+
20
+ export function UserInvitationsCard({
21
+ className,
22
+ classNames,
23
+ localization: localizationProp,
24
+ ...props
25
+ }: SettingsCardProps) {
26
+ const {
27
+ hooks: { useListUserInvitations, useListOrganizations },
28
+ localization: contextLocalization
29
+ } = useContext(AuthUIContext)
30
+
31
+ const localization = useMemo(
32
+ () => ({ ...contextLocalization, ...localizationProp }),
33
+ [contextLocalization, localizationProp]
34
+ )
35
+
36
+ const { data: invitations, refetch: refetchInvitations } =
37
+ useListUserInvitations()
38
+ const { refetch: refetchOrganizations } = useListOrganizations()
39
+
40
+ const handleRefresh = async () => {
41
+ await refetchInvitations?.()
42
+ await refetchOrganizations?.()
43
+ }
44
+
45
+ const pendingInvitations = invitations?.filter(
46
+ (invitation) => invitation.status === "pending"
47
+ )
48
+
49
+ if (!pendingInvitations?.length) return null
50
+
51
+ return (
52
+ <SettingsCard
53
+ className={className}
54
+ classNames={classNames}
55
+ title={localization.PENDING_INVITATIONS}
56
+ description={
57
+ localization.PENDING_USER_INVITATIONS_DESCRIPTION ||
58
+ localization.PENDING_INVITATIONS_DESCRIPTION
59
+ }
60
+ {...props}
61
+ >
62
+ <CardContent className={cn("grid gap-4", classNames?.content)}>
63
+ {pendingInvitations.map((invitation) => (
64
+ <UserInvitationRow
65
+ key={invitation.id}
66
+ classNames={classNames}
67
+ invitation={{
68
+ id: invitation.id,
69
+ email: invitation.email,
70
+ role: invitation.role,
71
+ status: invitation.status,
72
+ expiresAt: invitation.expiresAt
73
+ }}
74
+ onChanged={handleRefresh}
75
+ />
76
+ ))}
77
+ </CardContent>
78
+ </SettingsCard>
79
+ )
80
+ }
81
+
82
+ function UserInvitationRow({
83
+ classNames,
84
+ invitation,
85
+ onChanged
86
+ }: {
87
+ classNames?: SettingsCardProps["classNames"]
88
+ invitation: {
89
+ id: string
90
+ email: string
91
+ role: string
92
+ status: string
93
+ expiresAt: Date
94
+ }
95
+ onChanged?: () => unknown
96
+ }) {
97
+ const {
98
+ authClient,
99
+ organization: organizationOptions,
100
+ localization: contextLocalization,
101
+ toast
102
+ } = useContext(AuthUIContext)
103
+
104
+ const localization = contextLocalization
105
+
106
+ const [isLoading, setIsLoading] = useState(false)
107
+
108
+ const builtInRoles = [
109
+ { role: "owner", label: localization.OWNER },
110
+ { role: "admin", label: localization.ADMIN },
111
+ { role: "member", label: localization.MEMBER }
112
+ ]
113
+
114
+ const roles = [...builtInRoles, ...(organizationOptions?.customRoles || [])]
115
+ const role = roles.find((r) => r.role === invitation.role)
116
+
117
+ const handleAccept = async () => {
118
+ setIsLoading(true)
119
+
120
+ try {
121
+ await authClient.organization.acceptInvitation({
122
+ invitationId: invitation.id,
123
+ fetchOptions: { throw: true }
124
+ })
125
+
126
+ await onChanged?.()
127
+
128
+ toast({
129
+ variant: "success",
130
+ message: localization.INVITATION_ACCEPTED
131
+ })
132
+ } catch (error) {
133
+ toast({
134
+ variant: "error",
135
+ message: getLocalizedError({ error, localization })
136
+ })
137
+ }
138
+
139
+ setIsLoading(false)
140
+ }
141
+
142
+ const handleReject = async () => {
143
+ setIsLoading(true)
144
+
145
+ try {
146
+ await authClient.organization.rejectInvitation({
147
+ invitationId: invitation.id,
148
+ fetchOptions: { throw: true }
149
+ })
150
+
151
+ await onChanged?.()
152
+
153
+ toast({
154
+ variant: "success",
155
+ message: localization.INVITATION_REJECTED
156
+ })
157
+ } catch (error) {
158
+ toast({
159
+ variant: "error",
160
+ message: getLocalizedError({ error, localization })
161
+ })
162
+ }
163
+
164
+ setIsLoading(false)
165
+ }
166
+
167
+ return (
168
+ <Card className={cn("flex-row items-center p-4", classNames?.cell)}>
169
+ <div className="flex flex-1 items-center gap-2">
170
+ <UserAvatar
171
+ className="my-0.5"
172
+ user={{ email: invitation.email }}
173
+ localization={localization}
174
+ />
175
+
176
+ <div className="grid flex-1 text-left leading-tight">
177
+ <span className="truncate font-semibold text-sm">
178
+ {invitation.email}
179
+ </span>
180
+
181
+ <span className="truncate text-muted-foreground text-xs">
182
+ {localization.EXPIRES}{" "}
183
+ {invitation.expiresAt.toLocaleDateString()}
184
+ </span>
185
+ </div>
186
+ </div>
187
+
188
+ <span className="truncate text-sm opacity-70">{role?.label}</span>
189
+
190
+ <div className="flex items-center gap-2">
191
+ <DropdownMenu>
192
+ <DropdownMenuTrigger asChild>
193
+ <Button
194
+ className={cn(
195
+ "relative ms-auto",
196
+ classNames?.button,
197
+ classNames?.outlineButton
198
+ )}
199
+ disabled={isLoading}
200
+ size="icon"
201
+ type="button"
202
+ variant="outline"
203
+ >
204
+ {isLoading ? (
205
+ <Loader2 className="animate-spin" />
206
+ ) : (
207
+ <EllipsisIcon className={classNames?.icon} />
208
+ )}
209
+ </Button>
210
+ </DropdownMenuTrigger>
211
+
212
+ <DropdownMenuContent
213
+ onCloseAutoFocus={(e) => e.preventDefault()}
214
+ >
215
+ <DropdownMenuItem
216
+ onClick={handleAccept}
217
+ disabled={isLoading}
218
+ >
219
+ <CheckIcon className={classNames?.icon} />
220
+
221
+ {localization.ACCEPT}
222
+ </DropdownMenuItem>
223
+
224
+ <DropdownMenuItem
225
+ onClick={handleReject}
226
+ disabled={isLoading}
227
+ variant="destructive"
228
+ >
229
+ <XIcon className={classNames?.icon} />
230
+
231
+ {localization.REJECT}
232
+ </DropdownMenuItem>
233
+ </DropdownMenuContent>
234
+ </DropdownMenu>
235
+ </div>
236
+ </Card>
237
+ )
238
+ }
@@ -0,0 +1,56 @@
1
+ "use client"
2
+
3
+ import { EyeIcon, EyeOffIcon } from "lucide-react"
4
+ import { type ComponentProps, useState } from "react"
5
+
6
+ import { cn } from "../lib/utils"
7
+ import { Button } from "./ui/button"
8
+ import { Input } from "./ui/input"
9
+
10
+ export function PasswordInput({
11
+ className,
12
+ enableToggle,
13
+ onChange,
14
+ ...props
15
+ }: ComponentProps<typeof Input> & { enableToggle?: boolean }) {
16
+ const [disabled, setDisabled] = useState(true)
17
+ const [isVisible, setIsVisible] = useState(false)
18
+
19
+ return (
20
+ <div className="relative">
21
+ <Input
22
+ className={cn(enableToggle && "pr-10", className)}
23
+ {...props}
24
+ type={isVisible && enableToggle ? "text" : "password"}
25
+ onChange={(event) => {
26
+ setDisabled(!event.target.value)
27
+ onChange?.(event)
28
+ }}
29
+ />
30
+
31
+ {enableToggle && (
32
+ <>
33
+ <Button
34
+ className="!bg-transparent absolute top-0 right-0"
35
+ disabled={disabled}
36
+ size="icon"
37
+ type="button"
38
+ variant="ghost"
39
+ onClick={() => setIsVisible(!isVisible)}
40
+ >
41
+ {isVisible ? <EyeIcon /> : <EyeOffIcon />}
42
+ </Button>
43
+
44
+ <style>{`
45
+ .hide-password-toggle::-ms-reveal,
46
+ .hide-password-toggle::-ms-clear {
47
+ visibility: hidden;
48
+ pointer-events: none;
49
+ display: none;
50
+ }
51
+ `}</style>
52
+ </>
53
+ )}
54
+ </div>
55
+ )
56
+ }