@better-auth-ui/heroui 1.6.0 → 1.6.2

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 (221) hide show
  1. package/dist/components/auth/auth-provider.d.ts +1 -1
  2. package/dist/components/auth/auth-provider.js +15 -11
  3. package/dist/components/auth/auth.d.ts +3 -3
  4. package/dist/components/auth/auth.js +36 -41
  5. package/dist/components/auth/field-separator.d.ts +1 -1
  6. package/dist/components/auth/field-separator.js +17 -4
  7. package/dist/components/auth/forgot-password.d.ts +1 -1
  8. package/dist/components/auth/forgot-password.js +69 -27
  9. package/dist/components/auth/magic-link-button.d.ts +1 -1
  10. package/dist/components/auth/magic-link-button.js +15 -18
  11. package/dist/components/auth/magic-link.d.ts +2 -2
  12. package/dist/components/auth/magic-link.js +110 -42
  13. package/dist/components/auth/passkey-button.d.ts +4 -0
  14. package/dist/components/auth/passkey-button.js +24 -0
  15. package/dist/components/auth/provider-buttons.d.ts +1 -1
  16. package/dist/components/auth/provider-buttons.js +26 -33
  17. package/dist/components/auth/reset-password.d.ts +1 -1
  18. package/dist/components/auth/reset-password.js +146 -57
  19. package/dist/components/auth/sign-in.d.ts +2 -2
  20. package/dist/components/auth/sign-in.js +163 -63
  21. package/dist/components/auth/sign-out.js +26 -32
  22. package/dist/components/auth/sign-up.d.ts +2 -2
  23. package/dist/components/auth/sign-up.js +240 -70
  24. package/dist/components/email/email-changed-email.d.ts +2 -2
  25. package/dist/components/email/email-changed-email.js +29 -22
  26. package/dist/components/email/email-verification-email.d.ts +2 -2
  27. package/dist/components/email/email-verification-email.js +29 -22
  28. package/dist/components/email/magic-link-email.d.ts +2 -2
  29. package/dist/components/email/magic-link-email.js +29 -22
  30. package/dist/components/email/new-device-email.d.ts +2 -2
  31. package/dist/components/email/new-device-email.js +29 -22
  32. package/dist/components/email/otp-email.d.ts +2 -2
  33. package/dist/components/email/otp-email.js +28 -21
  34. package/dist/components/email/password-changed-email.d.ts +2 -2
  35. package/dist/components/email/password-changed-email.js +29 -22
  36. package/dist/components/email/reset-password-email.d.ts +2 -2
  37. package/dist/components/email/reset-password-email.js +29 -22
  38. package/dist/components/settings/account/account-settings.d.ts +2 -2
  39. package/dist/components/settings/account/account-settings.js +22 -19
  40. package/dist/components/settings/account/appearance.d.ts +1 -1
  41. package/dist/components/settings/account/appearance.js +70 -27
  42. package/dist/components/settings/account/change-avatar.js +88 -55
  43. package/dist/components/settings/account/change-email.d.ts +1 -1
  44. package/dist/components/settings/account/change-email.js +56 -28
  45. package/dist/components/settings/account/manage-account.d.ts +1 -1
  46. package/dist/components/settings/account/manage-account.js +50 -31
  47. package/dist/components/settings/account/manage-accounts.d.ts +1 -1
  48. package/dist/components/settings/account/manage-accounts.js +32 -36
  49. package/dist/components/settings/account/user-profile.d.ts +3 -3
  50. package/dist/components/settings/account/user-profile.js +105 -22
  51. package/dist/components/settings/security/active-session.d.ts +1 -1
  52. package/dist/components/settings/security/active-session.js +60 -51
  53. package/dist/components/settings/security/active-sessions.d.ts +1 -1
  54. package/dist/components/settings/security/active-sessions.js +32 -26
  55. package/dist/components/settings/security/change-password.d.ts +1 -1
  56. package/dist/components/settings/security/change-password.js +189 -76
  57. package/dist/components/settings/security/danger-zone.d.ts +2 -2
  58. package/dist/components/settings/security/danger-zone.js +17 -11
  59. package/dist/components/settings/security/delete-user.d.ts +1 -1
  60. package/dist/components/settings/security/delete-user.js +96 -46
  61. package/dist/components/settings/security/linked-account.d.ts +1 -1
  62. package/dist/components/settings/security/linked-account.js +61 -47
  63. package/dist/components/settings/security/linked-accounts.d.ts +1 -1
  64. package/dist/components/settings/security/linked-accounts.js +43 -40
  65. package/dist/components/settings/security/passkey.d.ts +8 -0
  66. package/dist/components/settings/security/passkey.js +43 -0
  67. package/dist/components/settings/security/passkeys.d.ts +6 -0
  68. package/dist/components/settings/security/passkeys.js +53 -0
  69. package/dist/components/settings/security/security-settings.d.ts +2 -2
  70. package/dist/components/settings/security/security-settings.js +24 -20
  71. package/dist/components/settings/settings.d.ts +3 -3
  72. package/dist/components/settings/settings.js +44 -27
  73. package/dist/components/user/switch-account-item.d.ts +1 -1
  74. package/dist/components/user/switch-account-item.js +19 -15
  75. package/dist/components/user/switch-account-menu.js +27 -28
  76. package/dist/components/user/user-avatar.d.ts +3 -3
  77. package/dist/components/user/user-avatar.js +28 -30
  78. package/dist/components/user/user-button.d.ts +1 -1
  79. package/dist/components/user/user-button.js +90 -23
  80. package/dist/components/user/user-view.d.ts +3 -3
  81. package/dist/components/user/user-view.js +36 -23
  82. package/dist/core.d.ts +1 -1
  83. package/dist/index.d.ts +35 -33
  84. package/dist/index.js +36 -33
  85. package/dist/react-exports.d.ts +1 -1
  86. package/package.json +17 -10
  87. package/src/components/auth/auth.tsx +1 -1
  88. package/src/components/auth/magic-link.tsx +4 -0
  89. package/src/components/auth/passkey-button.tsx +36 -0
  90. package/src/components/auth/sign-in.tsx +67 -30
  91. package/src/components/auth/sign-up.tsx +97 -3
  92. package/src/components/settings/account/user-profile.tsx +121 -6
  93. package/src/components/settings/security/passkey.tsx +51 -0
  94. package/src/components/settings/security/passkeys.tsx +104 -0
  95. package/src/components/settings/security/security-settings.tsx +3 -1
  96. package/src/components/settings/settings.tsx +1 -1
  97. package/src/index.tsx +2 -0
  98. package/dist/components/account/account.d.ts +0 -18
  99. package/dist/components/account/account.js +0 -24
  100. package/dist/components/account/settings/account-settings.d.ts +0 -5
  101. package/dist/components/account/settings/account-settings.js +0 -6
  102. package/dist/components/account/settings/settings.d.ts +0 -5
  103. package/dist/components/account/settings/settings.js +0 -5
  104. package/dist/components/account/settings/user-profile.d.ts +0 -5
  105. package/dist/components/account/settings/user-profile.js +0 -20
  106. package/dist/components/settings/account/accounts.d.ts +0 -14
  107. package/dist/components/settings/account/accounts.js +0 -26
  108. package/dist/components/settings/account/theme-selector.d.ts +0 -16
  109. package/dist/components/settings/account/theme-selector.js +0 -33
  110. package/dist/components/settings/account/theme-settings.d.ts +0 -16
  111. package/dist/components/settings/account/theme-settings.js +0 -31
  112. package/dist/components/settings/account-settings.d.ts +0 -5
  113. package/dist/components/settings/account-settings.js +0 -6
  114. package/dist/components/settings/account.d.ts +0 -18
  115. package/dist/components/settings/account.js +0 -24
  116. package/dist/components/settings/security/connected-account.d.ts +0 -16
  117. package/dist/components/settings/security/connected-account.js +0 -46
  118. package/dist/components/settings/security/connected-accounts.d.ts +0 -15
  119. package/dist/components/settings/security/connected-accounts.js +0 -31
  120. package/dist/components/settings/security/sessions.d.ts +0 -14
  121. package/dist/components/settings/security/sessions.js +0 -40
  122. package/dist/components/settings/settings/account-settings.d.ts +0 -5
  123. package/dist/components/settings/settings/account-settings.js +0 -6
  124. package/dist/components/settings/settings/user-profile.d.ts +0 -5
  125. package/dist/components/settings/settings/user-profile.js +0 -20
  126. package/dist/components/settings/user-profile.d.ts +0 -5
  127. package/dist/components/settings/user-profile.js +0 -20
  128. package/dist/components/user/switch-account-popover.d.ts +0 -10
  129. package/dist/components/user/switch-account-popover.js +0 -25
  130. package/dist/components/user/switch-account-submenu.d.ts +0 -10
  131. package/dist/components/user/switch-account-submenu.js +0 -25
  132. package/dist/hooks/use-auth.d.ts +0 -2
  133. package/dist/hooks/use-auth.js +0 -8
  134. package/dist/hooks/use-redirect-to.d.ts +0 -8
  135. package/dist/hooks/use-redirect-to.js +0 -19
  136. package/dist/hooks/use-sign-in.d.ts +0 -8
  137. package/dist/hooks/use-sign-in.js +0 -53
  138. package/dist/lib/utils.d.ts +0 -2
  139. package/dist/lib/utils.js +0 -5
  140. package/dist/server.d.ts +0 -1
  141. package/dist/server.js +0 -1
  142. package/dist/src/components/auth/auth-provider.d.ts +0 -8
  143. package/dist/src/components/auth/auth-provider.js +0 -13
  144. package/dist/src/components/auth/auth.d.ts +0 -22
  145. package/dist/src/components/auth/auth.js +0 -42
  146. package/dist/src/components/auth/field-separator.d.ts +0 -4
  147. package/dist/src/components/auth/field-separator.js +0 -5
  148. package/dist/src/components/auth/forgot-password.d.ts +0 -15
  149. package/dist/src/components/auth/forgot-password.js +0 -29
  150. package/dist/src/components/auth/magic-link-button.d.ts +0 -13
  151. package/dist/src/components/auth/magic-link-button.js +0 -20
  152. package/dist/src/components/auth/magic-link.d.ts +0 -17
  153. package/dist/src/components/auth/magic-link.js +0 -37
  154. package/dist/src/components/auth/provider-buttons.d.ts +0 -19
  155. package/dist/src/components/auth/provider-buttons.js +0 -35
  156. package/dist/src/components/auth/reset-password.d.ts +0 -11
  157. package/dist/src/components/auth/reset-password.js +0 -59
  158. package/dist/src/components/auth/sign-in.d.ts +0 -14
  159. package/dist/src/components/auth/sign-in.js +0 -58
  160. package/dist/src/components/auth/sign-out.d.ts +0 -11
  161. package/dist/src/components/auth/sign-out.js +0 -34
  162. package/dist/src/components/auth/sign-up.d.ts +0 -19
  163. package/dist/src/components/auth/sign-up.js +0 -65
  164. package/dist/src/components/email/email-changed-email.d.ts +0 -3
  165. package/dist/src/components/email/email-changed-email.js +0 -23
  166. package/dist/src/components/email/email-verification-email.d.ts +0 -3
  167. package/dist/src/components/email/email-verification-email.js +0 -23
  168. package/dist/src/components/email/magic-link-email.d.ts +0 -3
  169. package/dist/src/components/email/magic-link-email.js +0 -23
  170. package/dist/src/components/email/new-device-email.d.ts +0 -3
  171. package/dist/src/components/email/new-device-email.js +0 -23
  172. package/dist/src/components/email/otp-email.d.ts +0 -3
  173. package/dist/src/components/email/otp-email.js +0 -22
  174. package/dist/src/components/email/password-changed-email.d.ts +0 -3
  175. package/dist/src/components/email/password-changed-email.js +0 -23
  176. package/dist/src/components/email/reset-password-email.d.ts +0 -3
  177. package/dist/src/components/email/reset-password-email.js +0 -23
  178. package/dist/src/components/settings/account/account-settings.d.ts +0 -13
  179. package/dist/src/components/settings/account/account-settings.js +0 -19
  180. package/dist/src/components/settings/account/appearance.d.ts +0 -16
  181. package/dist/src/components/settings/account/appearance.js +0 -28
  182. package/dist/src/components/settings/account/change-email.d.ts +0 -15
  183. package/dist/src/components/settings/account/change-email.js +0 -35
  184. package/dist/src/components/settings/account/manage-account.d.ts +0 -19
  185. package/dist/src/components/settings/account/manage-account.js +0 -27
  186. package/dist/src/components/settings/account/manage-accounts.d.ts +0 -14
  187. package/dist/src/components/settings/account/manage-accounts.js +0 -27
  188. package/dist/src/components/settings/account/user-profile.d.ts +0 -13
  189. package/dist/src/components/settings/account/user-profile.js +0 -29
  190. package/dist/src/components/settings/security/active-session.d.ts +0 -14
  191. package/dist/src/components/settings/security/active-session.js +0 -35
  192. package/dist/src/components/settings/security/active-sessions.d.ts +0 -14
  193. package/dist/src/components/settings/security/active-sessions.js +0 -29
  194. package/dist/src/components/settings/security/change-password.d.ts +0 -15
  195. package/dist/src/components/settings/security/change-password.js +0 -57
  196. package/dist/src/components/settings/security/linked-account.d.ts +0 -16
  197. package/dist/src/components/settings/security/linked-account.js +0 -46
  198. package/dist/src/components/settings/security/linked-accounts.d.ts +0 -15
  199. package/dist/src/components/settings/security/linked-accounts.js +0 -31
  200. package/dist/src/components/settings/security/security-settings.d.ts +0 -15
  201. package/dist/src/components/settings/security/security-settings.js +0 -18
  202. package/dist/src/components/settings/settings.d.ts +0 -29
  203. package/dist/src/components/settings/settings.js +0 -39
  204. package/dist/src/components/user/switch-account-item.d.ts +0 -16
  205. package/dist/src/components/user/switch-account-item.js +0 -14
  206. package/dist/src/components/user/switch-account-menu.d.ts +0 -10
  207. package/dist/src/components/user/switch-account-menu.js +0 -23
  208. package/dist/src/components/user/user-avatar.d.ts +0 -24
  209. package/dist/src/components/user/user-avatar.js +0 -31
  210. package/dist/src/components/user/user-button.d.ts +0 -21
  211. package/dist/src/components/user/user-button.js +0 -24
  212. package/dist/src/components/user/user-view.d.ts +0 -21
  213. package/dist/src/components/user/user-view.js +0 -24
  214. package/dist/src/core.d.ts +0 -1
  215. package/dist/src/core.js +0 -1
  216. package/dist/src/index.d.ts +0 -31
  217. package/dist/src/index.js +0 -32
  218. package/dist/src/lib/utils.d.ts +0 -2
  219. package/dist/src/lib/utils.js +0 -5
  220. package/dist/src/react-exports.d.ts +0 -1
  221. package/dist/src/react-exports.js +0 -1
@@ -1,20 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useAuth, useUpdateUser } from "@better-auth-ui/react";
3
- import { CheckIcon, PencilIcon } from "@heroicons/react/24/outline";
4
- import { Button, Card, Description, FieldError, Fieldset, Form, Input, Label, Skeleton, Spinner, TextField } from "@heroui/react";
5
- import { UserAvatar } from "../user/user-avatar";
6
- export function UserProfile({ className, ...config }) {
7
- const { authClient, localization } = useAuth(config);
8
- const { data: sessionData, isPending: isSessionPending } = authClient.useSession();
9
- const [state, formAction, isPending] = useUpdateUser(config);
10
- if (isSessionPending) {
11
- return _jsx(UserProfileSkeleton, {});
12
- }
13
- return (_jsx(Card, { className: "p-4 md:p-6", children: _jsx(Form, { action: formAction, children: _jsxs(Fieldset, { className: "w-full gap-4 md:gap-6", children: [_jsx(Fieldset.Legend, { className: "text-xl", children: localization.settings.profile }), _jsx(Description, {}), _jsxs("div", { className: "flex items-center gap-3", children: [_jsxs(Button, { type: "button", isIconOnly: true, variant: "ghost", className: "p-0 h-auto w-auto rounded-full", children: [_jsx(UserAvatar, { ...config, size: "lg" }), _jsx("span", { className: "absolute right-0 bottom-0 size-3.5 rounded-full bg-background ring-2 ring-surface-quaternary flex items-center justify-center", children: _jsx(PencilIcon, { className: "size-2 text-muted" }) })] }), _jsxs("div", { className: "flex flex-col gap-1", children: [_jsx("p", { className: "text-sm font-medium", children: sessionData?.user?.displayUsername ||
14
- sessionData?.user?.name ||
15
- sessionData?.user?.email }), (sessionData?.user?.displayUsername ||
16
- sessionData?.user?.name) && (_jsx("p", { className: "text-muted text-xs leading-none", children: sessionData?.user?.email }))] })] }), _jsx(Fieldset.Group, { children: _jsxs(TextField, { name: "name", defaultValue: sessionData?.user?.name || state.name, isDisabled: isPending, children: [_jsx(Label, { children: localization.auth.name }), _jsx(Input, { placeholder: localization.auth.name }), _jsx(FieldError, {})] }) }), _jsx(Fieldset.Actions, { children: _jsxs(Button, { type: "submit", isPending: isPending, children: [isPending ? (_jsx(Spinner, { color: "current", size: "sm" })) : (_jsx(CheckIcon, { className: "size-4" })), localization.settings.saveChanges] }) })] }) }) }));
17
- }
18
- function UserProfileSkeleton() {
19
- return (_jsxs(Card, { className: "p-4 md:p-6 gap-4 md:gap-6", children: [_jsx(Skeleton, { className: "h-7 w-16 rounded-xl" }), _jsxs("div", { className: "flex items-center gap-3", children: [_jsx(Skeleton, { className: "size-12 rounded-full" }), _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Skeleton, { className: "h-4 mt-0.5 w-24 rounded-lg" }), _jsx(Skeleton, { className: "h-3 mt-0.5 w-32 rounded-lg" })] })] }), _jsxs("div", { className: "flex flex-col gap-1", children: [_jsx(Skeleton, { className: "h-4 w-12 my-0.5 rounded-lg" }), _jsx(Skeleton, { className: "h-9 w-full rounded-xl" })] }), _jsx(Skeleton, { className: "h-10 md:h-9 w-36 rounded-full mt-1" })] }));
20
- }
@@ -1,10 +0,0 @@
1
- /**
2
- * Render the popover content for switching between multiple authenticated sessions.
3
- *
4
- * Shows the current session with a checkmark, lists other device sessions that can be activated,
5
- * and provides an option to add a new account. This component should be rendered inside a
6
- * Dropdown.SubmenuTrigger to defer the useListDeviceSessions query until the submenu is opened.
7
- *
8
- * @returns The switch account popover content as a JSX element
9
- */
10
- export declare function SwitchAccountPopover(): import("react/jsx-runtime").JSX.Element;
@@ -1,25 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useAuth, useListDeviceSessions, useSession, useSetActiveSession } from "@better-auth-ui/react";
3
- import { Check, CirclePlus } from "@gravity-ui/icons";
4
- import { Dropdown, Label, Separator } from "@heroui/react";
5
- import { UserView } from "./user-view";
6
- /**
7
- * Render the popover content for switching between multiple authenticated sessions.
8
- *
9
- * Shows the current session with a checkmark, lists other device sessions that can be activated,
10
- * and provides an option to add a new account. This component should be rendered inside a
11
- * Dropdown.SubmenuTrigger to defer the useListDeviceSessions query until the submenu is opened.
12
- *
13
- * @returns The switch account popover content as a JSX element
14
- */
15
- export function SwitchAccountPopover() {
16
- const { basePaths, viewPaths, localization } = useAuth();
17
- const { settingActiveSession, setActiveSession } = useSetActiveSession();
18
- const { data: sessionData } = useSession();
19
- const { data: deviceSessions } = useListDeviceSessions();
20
- return (_jsxs(Dropdown.Menu, { children: [_jsxs(Dropdown.Item, { className: "px-2", children: [_jsx(UserView, {}), _jsx(Check, { className: "ml-auto" })] }), deviceSessions
21
- ?.filter((deviceSession) => deviceSession.session.id !== sessionData?.session?.id)
22
- .map((deviceSession) => {
23
- return (_jsx(Dropdown.Item, { className: "px-2", isDisabled: !!settingActiveSession, onPress: () => setActiveSession(deviceSession.session.token), children: _jsx(UserView, { user: deviceSession.user }) }, deviceSession.session.id));
24
- }), _jsx(Separator, {}), _jsxs(Dropdown.Item, { textValue: localization.auth.addAccount, href: `${basePaths.auth}/${viewPaths.auth.signIn}`, children: [_jsx(CirclePlus, { className: "text-muted" }), _jsx(Label, { children: localization.auth.addAccount })] })] }));
25
- }
@@ -1,10 +0,0 @@
1
- /**
2
- * Render the popover content for switching between multiple authenticated sessions.
3
- *
4
- * Shows the current session with a checkmark, lists other device sessions that can be activated,
5
- * and provides an option to add a new account. This component should be rendered inside a
6
- * Dropdown.SubmenuTrigger to defer the useListDeviceSessions query until the submenu is opened.
7
- *
8
- * @returns The switch account submenu popover content as a JSX element
9
- */
10
- export declare function SwitchAccountSubmenu(): import("react/jsx-runtime").JSX.Element;
@@ -1,25 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useAuth, useListDeviceSessions, useSession, useSetActiveSession } from "@better-auth-ui/react";
3
- import { Check, CirclePlus } from "@gravity-ui/icons";
4
- import { Dropdown, Label, Separator } from "@heroui/react";
5
- import { UserView } from "./user-view";
6
- /**
7
- * Render the popover content for switching between multiple authenticated sessions.
8
- *
9
- * Shows the current session with a checkmark, lists other device sessions that can be activated,
10
- * and provides an option to add a new account. This component should be rendered inside a
11
- * Dropdown.SubmenuTrigger to defer the useListDeviceSessions query until the submenu is opened.
12
- *
13
- * @returns The switch account submenu popover content as a JSX element
14
- */
15
- export function SwitchAccountSubmenu() {
16
- const { basePaths, viewPaths, localization } = useAuth();
17
- const { settingActiveSession, setActiveSession } = useSetActiveSession();
18
- const { data: sessionData } = useSession();
19
- const { data: deviceSessions } = useListDeviceSessions();
20
- return (_jsx(Dropdown.Popover, { className: "min-w-40 md:min-w-56 max-w-[48svw]", children: _jsxs(Dropdown.Menu, { children: [_jsxs(Dropdown.Item, { className: "px-2", children: [_jsx(UserView, {}), _jsx(Check, { className: "ml-auto" })] }), deviceSessions
21
- ?.filter((deviceSession) => deviceSession.session.id !== sessionData?.session?.id)
22
- .map((deviceSession) => {
23
- return (_jsx(Dropdown.Item, { className: "px-2", isDisabled: !!settingActiveSession, onPress: () => setActiveSession(deviceSession.session.token), children: _jsx(UserView, { user: deviceSession.user }) }, deviceSession.session.id));
24
- }), _jsx(Separator, {}), _jsxs(Dropdown.Item, { textValue: localization.auth.addAccount, href: `${basePaths.auth}/${viewPaths.auth.signIn}`, children: [_jsx(CirclePlus, { className: "text-muted" }), _jsx(Label, { children: localization.auth.addAccount })] })] }) }));
25
- }
@@ -1,2 +0,0 @@
1
- import { type AnyAuthConfig } from "@better-auth-ui/react";
2
- export declare function useAuth(config?: AnyAuthConfig): import("@better-auth-ui/react").AuthConfig;
@@ -1,8 +0,0 @@
1
- import { useAuth as useAuthPrimitive } from "@better-auth-ui/react";
2
- import { toast } from "sonner";
3
- const extendConfig = {
4
- toast
5
- };
6
- export function useAuth(config) {
7
- return useAuthPrimitive();
8
- }
@@ -1,8 +0,0 @@
1
- import type { AnyAuthConfig } from "@better-auth-ui/react";
2
- /**
3
- * Redirects unauthenticated users to the sign-in page, preserving the current URL as a redirectTo query parameter.
4
- *
5
- * @param config - Optional partial AuthConfig used to customize auth behavior
6
- * @param shouldRedirect - Condition to check before redirecting (default: when user is not authenticated and not loading)
7
- */
8
- export declare function useRedirectTo(config?: AnyAuthConfig, shouldRedirect?: boolean): void;
@@ -1,19 +0,0 @@
1
- import { useEffect } from "react";
2
- import { useAuth } from "./use-auth";
3
- /**
4
- * Redirects unauthenticated users to the sign-in page, preserving the current URL as a redirectTo query parameter.
5
- *
6
- * @param config - Optional partial AuthConfig used to customize auth behavior
7
- * @param shouldRedirect - Condition to check before redirecting (default: when user is not authenticated and not loading)
8
- */
9
- export function useRedirectTo(config, shouldRedirect) {
10
- const { basePaths, viewPaths, replace } = useAuth(config);
11
- useEffect(() => {
12
- if (shouldRedirect === false)
13
- return;
14
- const currentURL = window.location.pathname + window.location.search;
15
- const redirectTo = encodeURIComponent(currentURL);
16
- const signInPath = `${basePaths.auth}/${viewPaths.auth.signIn}?redirectTo=${redirectTo}`;
17
- replace(signInPath);
18
- }, [basePaths.auth, viewPaths.auth.signIn, replace, shouldRedirect]);
19
- }
@@ -1,8 +0,0 @@
1
- import type { AuthConfig } from "@better-auth-ui/react";
2
- export declare function useSignIn(config: AuthConfig<{
3
- RESEND: string;
4
- VERIFICATION_EMAIL_SENT: string;
5
- }>): [state: {
6
- email: string;
7
- password: string;
8
- }, dispatch: (payload: FormData) => void, isPending: boolean];
@@ -1,53 +0,0 @@
1
- "use client";
2
- import { useActionState } from "react";
3
- export function useSignIn(config) {
4
- const { authClient, baseURL, emailAndPassword, localization, redirectTo, navigate, toast } = config;
5
- const { refetch } = authClient.useSession();
6
- const signInAction = async (_, formData) => {
7
- const email = formData.get("email");
8
- const password = formData.get("password");
9
- const rememberMe = formData.get("rememberMe") === "on";
10
- const { error } = await authClient.signIn.email({
11
- email,
12
- password,
13
- ...(emailAndPassword?.rememberMe ? { rememberMe } : {})
14
- }, { disableSignal: true });
15
- if (error) {
16
- if (error.code === "EMAIL_NOT_VERIFIED") {
17
- const toastId = toast.error(error.message, {
18
- action: {
19
- label: localization.RESEND,
20
- onClick: async () => {
21
- const callbackURL = `${baseURL ?? ""}${redirectTo}`;
22
- toast.dismiss?.(toastId);
23
- const { error } = await authClient.sendVerificationEmail({
24
- email,
25
- callbackURL
26
- });
27
- if (error) {
28
- toast.error(error.message);
29
- }
30
- else {
31
- toast.success(localization.VERIFICATION_EMAIL_SENT);
32
- }
33
- }
34
- }
35
- });
36
- }
37
- else {
38
- toast.error(error.message);
39
- }
40
- return {
41
- email,
42
- password: ""
43
- };
44
- }
45
- await refetch();
46
- navigate(redirectTo);
47
- return { email, password };
48
- };
49
- return useActionState(signInAction, {
50
- email: "",
51
- password: ""
52
- });
53
- }
@@ -1,2 +0,0 @@
1
- import { type ClassValue } from "clsx";
2
- export declare function cn(...inputs: ClassValue[]): string;
package/dist/lib/utils.js DELETED
@@ -1,5 +0,0 @@
1
- import { clsx } from "clsx";
2
- import { twMerge } from "tailwind-merge";
3
- export function cn(...inputs) {
4
- return twMerge(clsx(inputs));
5
- }
package/dist/server.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "@better-auth-ui/react/server";
package/dist/server.js DELETED
@@ -1 +0,0 @@
1
- export * from "@better-auth-ui/react/server";
@@ -1,8 +0,0 @@
1
- import { type AuthProviderProps } from "@better-auth-ui/react";
2
- /**
3
- * Provides an authentication context by rendering an auth provider with the sonner toast handler injected, forwarding remaining configuration and rendering `children` inside it.
4
- *
5
- * @param children - React nodes to render inside the authentication provider
6
- * @returns A React element that renders an authentication provider configured with the provided props and toast handler
7
- */
8
- export declare function AuthProvider({ children, navigate, ...config }: AuthProviderProps): import("react/jsx-runtime").JSX.Element;
@@ -1,13 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { AuthProvider as AuthProviderPrimitive } from "@better-auth-ui/react";
3
- import { RouterProvider } from "@heroui/react";
4
- import { toast } from "sonner";
5
- /**
6
- * Provides an authentication context by rendering an auth provider with the sonner toast handler injected, forwarding remaining configuration and rendering `children` inside it.
7
- *
8
- * @param children - React nodes to render inside the authentication provider
9
- * @returns A React element that renders an authentication provider configured with the provided props and toast handler
10
- */
11
- export function AuthProvider({ children, navigate, ...config }) {
12
- return (_jsx(AuthProviderPrimitive, { toast: toast, navigate: navigate, ...config, children: _jsx(RouterProvider, { navigate: (path) => navigate({ to: path }), children: children }) }));
13
- }
@@ -1,22 +0,0 @@
1
- import type { AuthView } from "@better-auth-ui/react/core";
2
- import type { CardProps } from "@heroui/react";
3
- import type { SocialLayout } from "./provider-buttons";
4
- export type AuthProps = {
5
- className?: string;
6
- path?: string;
7
- socialLayout?: SocialLayout;
8
- socialPosition?: "top" | "bottom";
9
- variant?: CardProps["variant"];
10
- view?: AuthView;
11
- };
12
- /**
13
- * Render the appropriate authentication view based on the provided `view` or `path`.
14
- *
15
- * @param path - Route path used to resolve an auth view when `view` is not provided
16
- * @param socialLayout - Social layout to apply to sign-in/sign-up/magic-link views
17
- * @param socialPosition - Position for social buttons ("top" or "bottom")
18
- * @param variant - Variant to apply to the card
19
- * @param view - Explicit auth view to render (e.g., "signIn", "signUp")
20
- * @returns The React element for the resolved authentication view
21
- */
22
- export declare function Auth({ path, socialLayout, socialPosition, view, ...props }: AuthProps & CardProps): import("react/jsx-runtime").JSX.Element;
@@ -1,42 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useAuth } from "@better-auth-ui/react";
3
- import { ForgotPassword } from "./forgot-password";
4
- import { MagicLink } from "./magic-link";
5
- import { ResetPassword } from "./reset-password";
6
- import { SignIn } from "./sign-in";
7
- import { SignOut } from "./sign-out";
8
- import { SignUp } from "./sign-up";
9
- /**
10
- * Render the appropriate authentication view based on the provided `view` or `path`.
11
- *
12
- * @param path - Route path used to resolve an auth view when `view` is not provided
13
- * @param socialLayout - Social layout to apply to sign-in/sign-up/magic-link views
14
- * @param socialPosition - Position for social buttons ("top" or "bottom")
15
- * @param variant - Variant to apply to the card
16
- * @param view - Explicit auth view to render (e.g., "signIn", "signUp")
17
- * @returns The React element for the resolved authentication view
18
- */
19
- export function Auth({ path, socialLayout, socialPosition, view, ...props }) {
20
- const { viewPaths } = useAuth();
21
- if (!view && !path) {
22
- throw new Error("[Better Auth UI] Either `view` or `path` must be provided");
23
- }
24
- const authPathViews = Object.fromEntries(Object.entries(viewPaths.auth).map(([k, v]) => [v, k]));
25
- const currentView = view || (path ? authPathViews[path] : undefined);
26
- switch (currentView) {
27
- case "signIn":
28
- return (_jsx(SignIn, { socialLayout: socialLayout, socialPosition: socialPosition, ...props }));
29
- case "signUp":
30
- return (_jsx(SignUp, { socialLayout: socialLayout, socialPosition: socialPosition, ...props }));
31
- case "magicLink":
32
- return (_jsx(MagicLink, { socialLayout: socialLayout, socialPosition: socialPosition, ...props }));
33
- case "forgotPassword":
34
- return _jsx(ForgotPassword, { ...props });
35
- case "resetPassword":
36
- return _jsx(ResetPassword, { ...props });
37
- case "signOut":
38
- return _jsx(SignOut, { ...props });
39
- default:
40
- throw new Error(`[Better Auth UI] Valid views are: ${Object.keys(viewPaths.auth).join(", ")}`);
41
- }
42
- }
@@ -1,4 +0,0 @@
1
- import type { ReactNode } from "react";
2
- export declare function FieldSeparator({ children }: {
3
- children: ReactNode;
4
- }): import("react/jsx-runtime").JSX.Element;
@@ -1,5 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Separator } from "@heroui/react";
3
- export function FieldSeparator({ children }) {
4
- return (_jsxs("div", { className: "flex items-center gap-4", children: [_jsx(Separator, { className: "flex-1" }), _jsx("p", { className: "text-xs text-muted shrink-0", children: children }), _jsx(Separator, { className: "flex-1" })] }));
5
- }
@@ -1,15 +0,0 @@
1
- import { type CardProps } from "@heroui/react";
2
- export type ForgotPasswordProps = {
3
- className?: string;
4
- variant?: CardProps["variant"];
5
- };
6
- /**
7
- * Render a card-based "Forgot Password" form that sends a password-reset email.
8
- *
9
- * The form displays an email input, submit button, and a link back to sign-in.
10
- * Toasts are displayed on success or error via the `useForgotPassword` hook.
11
- *
12
- * @param className - Optional additional CSS class names applied to the card
13
- * @returns The forgot-password form UI as a JSX element
14
- */
15
- export declare function ForgotPassword({ className, variant, ...props }: ForgotPasswordProps & CardProps): import("react/jsx-runtime").JSX.Element;
@@ -1,29 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useAuth, useRequestPasswordReset } from "@better-auth-ui/react";
3
- import { Button, Card, Description, FieldError, Fieldset, Form, Input, Label, Link, Spinner, TextField, toast } from "@heroui/react";
4
- import { cn } from "../../lib/utils";
5
- /**
6
- * Render a card-based "Forgot Password" form that sends a password-reset email.
7
- *
8
- * The form displays an email input, submit button, and a link back to sign-in.
9
- * Toasts are displayed on success or error via the `useForgotPassword` hook.
10
- *
11
- * @param className - Optional additional CSS class names applied to the card
12
- * @returns The forgot-password form UI as a JSX element
13
- */
14
- export function ForgotPassword({ className, variant, ...props }) {
15
- const { basePaths, localization, viewPaths, navigate } = useAuth();
16
- const { mutate: requestPasswordReset, isPending } = useRequestPasswordReset({
17
- onError: (error) => toast.danger(error.error?.message || error.message),
18
- onSuccess: () => {
19
- toast.success(localization.auth.passwordResetEmailSent);
20
- navigate({ to: `${basePaths.auth}/${viewPaths.auth.signIn}` });
21
- }
22
- });
23
- function handleSubmit(e) {
24
- e.preventDefault();
25
- const formData = new FormData(e.currentTarget);
26
- requestPasswordReset({ email: formData.get("email") });
27
- }
28
- return (_jsx(Card, { className: cn("w-full max-w-sm p-4 md:p-6", className), variant: variant, ...props, children: _jsx(Card.Content, { children: _jsx(Form, { onSubmit: handleSubmit, children: _jsxs(Fieldset, { className: "gap-4", children: [_jsx(Label, { className: "text-xl", children: localization.auth.forgotPassword }), _jsxs(TextField, { name: "email", type: "email", autoComplete: "email", isDisabled: isPending, children: [_jsx(Label, { children: localization.auth.email }), _jsx(Input, { placeholder: localization.auth.emailPlaceholder, required: true, variant: variant === "transparent" ? "primary" : "secondary" }), _jsx(FieldError, { className: "text-wrap" })] }), _jsx(Fieldset.Actions, { children: _jsxs(Button, { type: "submit", className: "w-full", isPending: isPending, children: [isPending && _jsx(Spinner, { color: "current", size: "sm" }), localization.auth.sendResetLink] }) }), _jsxs(Description, { className: "text-center text-sm", children: [localization.auth.rememberYourPassword, " ", _jsx(Link, { href: `${basePaths.auth}/${viewPaths.auth.signIn}`, className: "text-accent decoration-accent no-underline hover:underline", children: localization.auth.signIn })] })] }) }) }) }));
29
- }
@@ -1,13 +0,0 @@
1
- import type { AuthView } from "@better-auth-ui/core";
2
- export type MagicLinkButtonProps = {
3
- isPending: boolean;
4
- view?: AuthView;
5
- };
6
- /**
7
- * Renders a full-width tertiary link-style button that navigates to either the magic-link or sign-in route.
8
- *
9
- * @param isPending - If true, applies disabled styling and prevents interaction
10
- * @param view - Current auth view; when `"magicLink"`, the button targets the sign-in/password variant
11
- * @returns The rendered Link element with the appropriate href, icon, and label
12
- */
13
- export declare function MagicLinkButton({ isPending, view }: MagicLinkButtonProps): import("react/jsx-runtime").JSX.Element;
@@ -1,20 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useAuth } from "@better-auth-ui/react";
3
- import { Envelope, Lock } from "@gravity-ui/icons";
4
- import { Link } from "@heroui/react";
5
- import { buttonVariants } from "@heroui/styles";
6
- import { cn } from "../../lib/utils";
7
- /**
8
- * Renders a full-width tertiary link-style button that navigates to either the magic-link or sign-in route.
9
- *
10
- * @param isPending - If true, applies disabled styling and prevents interaction
11
- * @param view - Current auth view; when `"magicLink"`, the button targets the sign-in/password variant
12
- * @returns The rendered Link element with the appropriate href, icon, and label
13
- */
14
- export function MagicLinkButton({ isPending, view }) {
15
- const { basePaths, viewPaths, localization } = useAuth();
16
- const isMagicLinkView = view === "magicLink";
17
- return (_jsxs(Link, { href: `${basePaths.auth}/${isMagicLinkView ? viewPaths.auth.signIn : viewPaths.auth.magicLink}`, className: cn(buttonVariants({ variant: "tertiary" }), "w-full gap-2", isPending && "status-disabled pointer-events-none"), children: [isMagicLinkView ? _jsx(Lock, {}) : _jsx(Envelope, {}), localization.auth.continueWith.replace("{{provider}}", isMagicLinkView
18
- ? localization.auth.password
19
- : localization.auth.magicLink)] }));
20
- }
@@ -1,17 +0,0 @@
1
- import { type CardProps } from "@heroui/react";
2
- import { type SocialLayout } from "./provider-buttons";
3
- export type MagicLinkProps = {
4
- className?: string;
5
- socialLayout?: SocialLayout;
6
- socialPosition?: "top" | "bottom";
7
- variant?: CardProps["variant"];
8
- };
9
- /**
10
- * Render a card-based sign-in form that sends an email magic link and optionally shows social provider buttons.
11
- *
12
- * @param className - Additional CSS class names applied to the card container
13
- * @param socialLayout - Layout style for social provider buttons
14
- * @param socialPosition - Position of social provider buttons; `"top"` or `"bottom"`. Defaults to `"bottom"`.
15
- * @returns The magic-link sign-in UI as a JSX element
16
- */
17
- export declare function MagicLink({ className, socialLayout, socialPosition, variant, ...props }: MagicLinkProps & CardProps): import("react/jsx-runtime").JSX.Element;
@@ -1,37 +0,0 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useAuth, useSignInMagicLink, useSignInSocial } from "@better-auth-ui/react";
3
- import { Button, Card, Description, FieldError, Fieldset, Form, Input, Label, Link, Spinner, TextField, toast } from "@heroui/react";
4
- import { useState } from "react";
5
- import { cn } from "../../lib/utils";
6
- import { FieldSeparator } from "./field-separator";
7
- import { MagicLinkButton } from "./magic-link-button";
8
- import { ProviderButtons } from "./provider-buttons";
9
- /**
10
- * Render a card-based sign-in form that sends an email magic link and optionally shows social provider buttons.
11
- *
12
- * @param className - Additional CSS class names applied to the card container
13
- * @param socialLayout - Layout style for social provider buttons
14
- * @param socialPosition - Position of social provider buttons; `"top"` or `"bottom"`. Defaults to `"bottom"`.
15
- * @returns The magic-link sign-in UI as a JSX element
16
- */
17
- export function MagicLink({ className, socialLayout, socialPosition = "bottom", variant, ...props }) {
18
- const { basePaths, baseURL, localization, redirectTo, socialProviders, viewPaths } = useAuth();
19
- const [email, setEmail] = useState("");
20
- const { mutate: signInMagicLink, isPending: magicLinkPending } = useSignInMagicLink({
21
- onError: (error) => toast.danger(error.error?.message || error.message),
22
- onSuccess: () => {
23
- setEmail("");
24
- toast.success(localization.auth.magicLinkSent);
25
- }
26
- });
27
- const { mutate: signInSocial, isPending: socialPending } = useSignInSocial({
28
- onError: (error) => toast.danger(error.error?.message || error.message)
29
- });
30
- const isPending = magicLinkPending || socialPending;
31
- const handleSubmit = (e) => {
32
- e.preventDefault();
33
- signInMagicLink({ email, callbackURL: `${baseURL}${redirectTo}` });
34
- };
35
- const showSeparator = socialProviders && socialProviders.length > 0;
36
- return (_jsx(Card, { className: cn("w-full max-w-sm p-4 md:p-6", className), variant: variant, ...props, children: _jsx(Card.Content, { children: _jsxs(Fieldset, { className: "gap-4", children: [_jsx(Label, { className: "text-xl", children: localization.auth.signIn }), socialPosition === "top" && (_jsxs(_Fragment, { children: [socialProviders && socialProviders.length > 0 && (_jsx(ProviderButtons, { socialLayout: socialLayout, signInSocial: signInSocial, isPending: isPending })), showSeparator && (_jsx(FieldSeparator, { children: localization.auth.or }))] })), _jsxs(Form, { onSubmit: handleSubmit, className: "flex flex-col gap-4", children: [_jsx(Fieldset.Group, { children: _jsxs(TextField, { name: "email", type: "email", autoComplete: "email", isDisabled: isPending, value: email, onChange: setEmail, children: [_jsx(Label, { children: localization.auth.email }), _jsx(Input, { placeholder: localization.auth.emailPlaceholder, required: true, variant: variant === "transparent" ? "primary" : "secondary" }), _jsx(FieldError, { className: "text-wrap" })] }) }), _jsxs(Fieldset.Actions, { className: "flex-col gap-3", children: [_jsxs(Button, { type: "submit", className: "w-full", isPending: isPending, children: [isPending && _jsx(Spinner, { color: "current", size: "sm" }), localization.auth.sendMagicLink] }), _jsx(MagicLinkButton, { view: "magicLink", isPending: isPending })] })] }), socialPosition === "bottom" && (_jsxs(_Fragment, { children: [showSeparator && (_jsx(FieldSeparator, { children: localization.auth.or })), socialProviders && socialProviders.length > 0 && (_jsx(ProviderButtons, { socialLayout: socialLayout, signInSocial: signInSocial, isPending: isPending }))] })), _jsxs(Description, { className: "text-center text-sm", children: [localization.auth.needToCreateAnAccount, " ", _jsx(Link, { href: `${basePaths.auth}/${viewPaths.auth.signUp}`, className: "text-accent decoration-accent no-underline hover:underline", children: localization.auth.signUp })] })] }) }) }));
37
- }
@@ -1,19 +0,0 @@
1
- import type { SocialProvider } from "better-auth/social-providers";
2
- export type ProviderButtonsProps = {
3
- isPending: boolean;
4
- socialLayout?: SocialLayout;
5
- signInSocial: (params: {
6
- provider: SocialProvider;
7
- callbackURL: string;
8
- }) => void;
9
- };
10
- export type SocialLayout = "auto" | "horizontal" | "vertical" | "grid";
11
- /**
12
- * Render social provider sign-in buttons and handle initiation and pending state.
13
- *
14
- * @param isPending - Disables all provider buttons when true.
15
- * @param socialLayout - Preferred layout for the buttons; `"auto"` picks `"horizontal"` when there are four or more providers, otherwise `"vertical"`.
16
- * @param signInSocial - Callback invoked with the provider and callbackURL when a button is clicked.
17
- * @returns The JSX element that renders the configured social provider buttons.
18
- */
19
- export declare function ProviderButtons({ isPending, socialLayout, signInSocial }: ProviderButtonsProps): import("react/jsx-runtime").JSX.Element;
@@ -1,35 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { getProviderName } from "@better-auth-ui/core";
3
- import { providerIcons, useAuth } from "@better-auth-ui/react";
4
- import { Button } from "@heroui/react";
5
- import { useMemo } from "react";
6
- import { cn } from "../../lib/utils";
7
- /**
8
- * Render social provider sign-in buttons and handle initiation and pending state.
9
- *
10
- * @param isPending - Disables all provider buttons when true.
11
- * @param socialLayout - Preferred layout for the buttons; `"auto"` picks `"horizontal"` when there are four or more providers, otherwise `"vertical"`.
12
- * @param signInSocial - Callback invoked with the provider and callbackURL when a button is clicked.
13
- * @returns The JSX element that renders the configured social provider buttons.
14
- */
15
- export function ProviderButtons({ isPending, socialLayout = "auto", signInSocial }) {
16
- const { baseURL, localization, redirectTo, socialProviders } = useAuth();
17
- const callbackURL = `${baseURL}${redirectTo}`;
18
- const resolvedSocialLayout = useMemo(() => {
19
- if (socialLayout === "auto") {
20
- if (socialProviders?.length && socialProviders.length >= 4) {
21
- return "horizontal";
22
- }
23
- return "vertical";
24
- }
25
- return socialLayout;
26
- }, [socialLayout, socialProviders?.length]);
27
- return (_jsx("div", { className: cn("gap-3", resolvedSocialLayout === "grid" && "grid grid-cols-2", resolvedSocialLayout === "vertical" && "flex flex-col", resolvedSocialLayout === "horizontal" && "flex flex-wrap"), children: socialProviders?.map((provider) => {
28
- const ProviderIcon = providerIcons[provider];
29
- return (_jsxs(Button, { className: cn("w-full", resolvedSocialLayout === "horizontal" && "flex-1"), variant: "tertiary", isPending: isPending, onPress: () => signInSocial({ provider, callbackURL }), children: [_jsx(ProviderIcon, {}), resolvedSocialLayout === "vertical"
30
- ? localization.auth.continueWith.replace("{{provider}}", getProviderName(provider))
31
- : resolvedSocialLayout === "grid"
32
- ? getProviderName(provider)
33
- : null] }, provider));
34
- }) }));
35
- }
@@ -1,11 +0,0 @@
1
- import { type CardProps } from "@heroui/react";
2
- export type ResetPasswordProps = {
3
- className?: string;
4
- variant?: CardProps["variant"];
5
- };
6
- /**
7
- * Renders a reset password form that verifies a "token" URL parameter on mount and redirects to sign-in if absent.
8
- *
9
- * Renders password (and optional confirm-password) inputs with visibility toggles, applies min/max length constraints from the auth configuration, shows field errors, and submits the new password to the auth client.
10
- */
11
- export declare function ResetPassword({ className, variant, ...props }: ResetPasswordProps & CardProps): import("react/jsx-runtime").JSX.Element;
@@ -1,59 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useAuth, useResetPassword } from "@better-auth-ui/react";
3
- import { Eye, EyeSlash } from "@gravity-ui/icons";
4
- import { Button, Card, Description, FieldError, Fieldset, Form, InputGroup, Label, Link, Spinner, TextField, toast } from "@heroui/react";
5
- import { useEffect, useState } from "react";
6
- import { cn } from "../../lib/utils";
7
- /**
8
- * Renders a reset password form that verifies a "token" URL parameter on mount and redirects to sign-in if absent.
9
- *
10
- * Renders password (and optional confirm-password) inputs with visibility toggles, applies min/max length constraints from the auth configuration, shows field errors, and submits the new password to the auth client.
11
- */
12
- export function ResetPassword({ className, variant, ...props }) {
13
- const { basePaths, emailAndPassword, localization, viewPaths, navigate } = useAuth();
14
- const { mutate: resetPassword, isPending } = useResetPassword({
15
- onError: (error) => toast.danger(error.error?.message || error.message),
16
- onSuccess: () => {
17
- toast.success(localization.auth.passwordResetSuccess);
18
- navigate({ to: `${basePaths.auth}/${viewPaths.auth.signIn}` });
19
- }
20
- });
21
- const [isPasswordVisible, setIsPasswordVisible] = useState(false);
22
- const [isConfirmPasswordVisible, setIsConfirmPasswordVisible] = useState(false);
23
- useEffect(() => {
24
- const searchParams = new URLSearchParams(window.location.search);
25
- const token = searchParams.get("token");
26
- if (!token) {
27
- toast.danger(localization.auth.invalidResetPasswordToken);
28
- navigate({ to: `${basePaths.auth}/${viewPaths.auth.signIn}` });
29
- }
30
- }, [
31
- basePaths.auth,
32
- localization.auth.invalidResetPasswordToken,
33
- viewPaths.auth.signIn,
34
- navigate
35
- ]);
36
- function handleSubmit(e) {
37
- e.preventDefault();
38
- const searchParams = new URLSearchParams(window.location.search);
39
- const token = searchParams.get("token");
40
- if (!token) {
41
- toast.danger(localization.auth.invalidResetPasswordToken);
42
- navigate({ to: `${basePaths.auth}/${viewPaths.auth.signIn}` });
43
- return;
44
- }
45
- const formData = new FormData(e.currentTarget);
46
- const password = formData.get("password");
47
- const confirmPassword = formData.get("confirmPassword");
48
- if (emailAndPassword?.confirmPassword && password !== confirmPassword) {
49
- toast.danger(localization.auth.passwordsDoNotMatch);
50
- return;
51
- }
52
- resetPassword({ token, newPassword: password });
53
- }
54
- return (_jsx(Card, { className: cn("w-full max-w-sm p-4 md:p-6", className), variant: variant, ...props, children: _jsx(Card.Content, { children: _jsx(Form, { onSubmit: handleSubmit, children: _jsxs(Fieldset, { className: "gap-4", children: [_jsx(Label, { className: "text-xl", children: localization.auth.resetPassword }), _jsxs(TextField, { minLength: emailAndPassword?.minPasswordLength, maxLength: emailAndPassword?.maxPasswordLength, name: "password", autoComplete: "new-password", isDisabled: isPending, children: [_jsx(Label, { children: localization.auth.password }), _jsxs(InputGroup, { variant: variant === "transparent" ? "primary" : "secondary", children: [_jsx(InputGroup.Input, { name: "password", placeholder: localization.auth.newPasswordPlaceholder, type: isPasswordVisible ? "text" : "password", required: true }), _jsx(InputGroup.Suffix, { className: "px-0", children: _jsx(Button, { isIconOnly: true, "aria-label": isPasswordVisible
55
- ? localization.auth.hidePassword
56
- : localization.auth.showPassword, size: "sm", variant: "ghost", onPress: () => setIsPasswordVisible(!isPasswordVisible), isDisabled: isPending, children: isPasswordVisible ? _jsx(EyeSlash, {}) : _jsx(Eye, {}) }) })] }), _jsx(FieldError, { className: "text-wrap" })] }), emailAndPassword?.confirmPassword && (_jsxs(TextField, { minLength: emailAndPassword?.minPasswordLength, maxLength: emailAndPassword?.maxPasswordLength, name: "confirmPassword", autoComplete: "new-password", isDisabled: isPending, children: [_jsx(Label, { children: localization.auth.confirmPassword }), _jsxs(InputGroup, { variant: variant === "transparent" ? "primary" : "secondary", children: [_jsx(InputGroup.Input, { placeholder: localization.auth.confirmPasswordPlaceholder, type: isConfirmPasswordVisible ? "text" : "password", required: true, name: "confirmPassword" }), _jsx(InputGroup.Suffix, { className: "px-0", children: _jsx(Button, { isIconOnly: true, "aria-label": isConfirmPasswordVisible
57
- ? localization.auth.hidePassword
58
- : localization.auth.showPassword, size: "sm", variant: "ghost", onPress: () => setIsConfirmPasswordVisible(!isConfirmPasswordVisible), isDisabled: isPending, children: isConfirmPasswordVisible ? _jsx(EyeSlash, {}) : _jsx(Eye, {}) }) })] }), _jsx(FieldError, { className: "text-wrap" })] })), _jsx(Fieldset.Actions, { children: _jsxs(Button, { type: "submit", className: "w-full", isPending: isPending, children: [isPending && _jsx(Spinner, { color: "current", size: "sm" }), localization.auth.resetPassword] }) }), _jsxs(Description, { className: "text-center text-sm", children: [localization.auth.rememberYourPassword, " ", _jsx(Link, { href: `${basePaths.auth}/${viewPaths.auth.signIn}`, className: "text-accent decoration-accent no-underline hover:underline", children: localization.auth.signIn })] })] }) }) }) }));
59
- }
@@ -1,14 +0,0 @@
1
- import { type CardProps } from "@heroui/react";
2
- import { type SocialLayout } from "./provider-buttons";
3
- export interface SignInProps {
4
- className?: string;
5
- socialLayout?: SocialLayout;
6
- socialPosition?: "top" | "bottom";
7
- variant?: CardProps["variant"];
8
- }
9
- /**
10
- * Render the sign-in UI using auth context for configuration and localization.
11
- *
12
- * @returns The sign-in JSX element containing email/password fields, optional magic-link button, and social provider buttons.
13
- */
14
- export declare function SignIn({ className, socialLayout, socialPosition, variant, ...props }: SignInProps & CardProps): import("react/jsx-runtime").JSX.Element;