@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.
- package/dist/components/auth/auth-provider.d.ts +1 -1
- package/dist/components/auth/auth-provider.js +15 -11
- package/dist/components/auth/auth.d.ts +3 -3
- package/dist/components/auth/auth.js +36 -41
- package/dist/components/auth/field-separator.d.ts +1 -1
- package/dist/components/auth/field-separator.js +17 -4
- package/dist/components/auth/forgot-password.d.ts +1 -1
- package/dist/components/auth/forgot-password.js +69 -27
- package/dist/components/auth/magic-link-button.d.ts +1 -1
- package/dist/components/auth/magic-link-button.js +15 -18
- package/dist/components/auth/magic-link.d.ts +2 -2
- package/dist/components/auth/magic-link.js +110 -42
- package/dist/components/auth/passkey-button.d.ts +4 -0
- package/dist/components/auth/passkey-button.js +24 -0
- package/dist/components/auth/provider-buttons.d.ts +1 -1
- package/dist/components/auth/provider-buttons.js +26 -33
- package/dist/components/auth/reset-password.d.ts +1 -1
- package/dist/components/auth/reset-password.js +146 -57
- package/dist/components/auth/sign-in.d.ts +2 -2
- package/dist/components/auth/sign-in.js +163 -63
- package/dist/components/auth/sign-out.js +26 -32
- package/dist/components/auth/sign-up.d.ts +2 -2
- package/dist/components/auth/sign-up.js +240 -70
- package/dist/components/email/email-changed-email.d.ts +2 -2
- package/dist/components/email/email-changed-email.js +29 -22
- package/dist/components/email/email-verification-email.d.ts +2 -2
- package/dist/components/email/email-verification-email.js +29 -22
- package/dist/components/email/magic-link-email.d.ts +2 -2
- package/dist/components/email/magic-link-email.js +29 -22
- package/dist/components/email/new-device-email.d.ts +2 -2
- package/dist/components/email/new-device-email.js +29 -22
- package/dist/components/email/otp-email.d.ts +2 -2
- package/dist/components/email/otp-email.js +28 -21
- package/dist/components/email/password-changed-email.d.ts +2 -2
- package/dist/components/email/password-changed-email.js +29 -22
- package/dist/components/email/reset-password-email.d.ts +2 -2
- package/dist/components/email/reset-password-email.js +29 -22
- package/dist/components/settings/account/account-settings.d.ts +2 -2
- package/dist/components/settings/account/account-settings.js +22 -19
- package/dist/components/settings/account/appearance.d.ts +1 -1
- package/dist/components/settings/account/appearance.js +70 -27
- package/dist/components/settings/account/change-avatar.js +88 -55
- package/dist/components/settings/account/change-email.d.ts +1 -1
- package/dist/components/settings/account/change-email.js +56 -28
- package/dist/components/settings/account/manage-account.d.ts +1 -1
- package/dist/components/settings/account/manage-account.js +50 -31
- package/dist/components/settings/account/manage-accounts.d.ts +1 -1
- package/dist/components/settings/account/manage-accounts.js +32 -36
- package/dist/components/settings/account/user-profile.d.ts +3 -3
- package/dist/components/settings/account/user-profile.js +105 -22
- package/dist/components/settings/security/active-session.d.ts +1 -1
- package/dist/components/settings/security/active-session.js +60 -51
- package/dist/components/settings/security/active-sessions.d.ts +1 -1
- package/dist/components/settings/security/active-sessions.js +32 -26
- package/dist/components/settings/security/change-password.d.ts +1 -1
- package/dist/components/settings/security/change-password.js +189 -76
- package/dist/components/settings/security/danger-zone.d.ts +2 -2
- package/dist/components/settings/security/danger-zone.js +17 -11
- package/dist/components/settings/security/delete-user.d.ts +1 -1
- package/dist/components/settings/security/delete-user.js +96 -46
- package/dist/components/settings/security/linked-account.d.ts +1 -1
- package/dist/components/settings/security/linked-account.js +61 -47
- package/dist/components/settings/security/linked-accounts.d.ts +1 -1
- package/dist/components/settings/security/linked-accounts.js +43 -40
- package/dist/components/settings/security/passkey.d.ts +8 -0
- package/dist/components/settings/security/passkey.js +43 -0
- package/dist/components/settings/security/passkeys.d.ts +6 -0
- package/dist/components/settings/security/passkeys.js +53 -0
- package/dist/components/settings/security/security-settings.d.ts +2 -2
- package/dist/components/settings/security/security-settings.js +24 -20
- package/dist/components/settings/settings.d.ts +3 -3
- package/dist/components/settings/settings.js +44 -27
- package/dist/components/user/switch-account-item.d.ts +1 -1
- package/dist/components/user/switch-account-item.js +19 -15
- package/dist/components/user/switch-account-menu.js +27 -28
- package/dist/components/user/user-avatar.d.ts +3 -3
- package/dist/components/user/user-avatar.js +28 -30
- package/dist/components/user/user-button.d.ts +1 -1
- package/dist/components/user/user-button.js +90 -23
- package/dist/components/user/user-view.d.ts +3 -3
- package/dist/components/user/user-view.js +36 -23
- package/dist/core.d.ts +1 -1
- package/dist/index.d.ts +35 -33
- package/dist/index.js +36 -33
- package/dist/react-exports.d.ts +1 -1
- package/package.json +17 -10
- package/src/components/auth/auth.tsx +1 -1
- package/src/components/auth/magic-link.tsx +4 -0
- package/src/components/auth/passkey-button.tsx +36 -0
- package/src/components/auth/sign-in.tsx +67 -30
- package/src/components/auth/sign-up.tsx +97 -3
- package/src/components/settings/account/user-profile.tsx +121 -6
- package/src/components/settings/security/passkey.tsx +51 -0
- package/src/components/settings/security/passkeys.tsx +104 -0
- package/src/components/settings/security/security-settings.tsx +3 -1
- package/src/components/settings/settings.tsx +1 -1
- package/src/index.tsx +2 -0
- package/dist/components/account/account.d.ts +0 -18
- package/dist/components/account/account.js +0 -24
- package/dist/components/account/settings/account-settings.d.ts +0 -5
- package/dist/components/account/settings/account-settings.js +0 -6
- package/dist/components/account/settings/settings.d.ts +0 -5
- package/dist/components/account/settings/settings.js +0 -5
- package/dist/components/account/settings/user-profile.d.ts +0 -5
- package/dist/components/account/settings/user-profile.js +0 -20
- package/dist/components/settings/account/accounts.d.ts +0 -14
- package/dist/components/settings/account/accounts.js +0 -26
- package/dist/components/settings/account/theme-selector.d.ts +0 -16
- package/dist/components/settings/account/theme-selector.js +0 -33
- package/dist/components/settings/account/theme-settings.d.ts +0 -16
- package/dist/components/settings/account/theme-settings.js +0 -31
- package/dist/components/settings/account-settings.d.ts +0 -5
- package/dist/components/settings/account-settings.js +0 -6
- package/dist/components/settings/account.d.ts +0 -18
- package/dist/components/settings/account.js +0 -24
- package/dist/components/settings/security/connected-account.d.ts +0 -16
- package/dist/components/settings/security/connected-account.js +0 -46
- package/dist/components/settings/security/connected-accounts.d.ts +0 -15
- package/dist/components/settings/security/connected-accounts.js +0 -31
- package/dist/components/settings/security/sessions.d.ts +0 -14
- package/dist/components/settings/security/sessions.js +0 -40
- package/dist/components/settings/settings/account-settings.d.ts +0 -5
- package/dist/components/settings/settings/account-settings.js +0 -6
- package/dist/components/settings/settings/user-profile.d.ts +0 -5
- package/dist/components/settings/settings/user-profile.js +0 -20
- package/dist/components/settings/user-profile.d.ts +0 -5
- package/dist/components/settings/user-profile.js +0 -20
- package/dist/components/user/switch-account-popover.d.ts +0 -10
- package/dist/components/user/switch-account-popover.js +0 -25
- package/dist/components/user/switch-account-submenu.d.ts +0 -10
- package/dist/components/user/switch-account-submenu.js +0 -25
- package/dist/hooks/use-auth.d.ts +0 -2
- package/dist/hooks/use-auth.js +0 -8
- package/dist/hooks/use-redirect-to.d.ts +0 -8
- package/dist/hooks/use-redirect-to.js +0 -19
- package/dist/hooks/use-sign-in.d.ts +0 -8
- package/dist/hooks/use-sign-in.js +0 -53
- package/dist/lib/utils.d.ts +0 -2
- package/dist/lib/utils.js +0 -5
- package/dist/server.d.ts +0 -1
- package/dist/server.js +0 -1
- package/dist/src/components/auth/auth-provider.d.ts +0 -8
- package/dist/src/components/auth/auth-provider.js +0 -13
- package/dist/src/components/auth/auth.d.ts +0 -22
- package/dist/src/components/auth/auth.js +0 -42
- package/dist/src/components/auth/field-separator.d.ts +0 -4
- package/dist/src/components/auth/field-separator.js +0 -5
- package/dist/src/components/auth/forgot-password.d.ts +0 -15
- package/dist/src/components/auth/forgot-password.js +0 -29
- package/dist/src/components/auth/magic-link-button.d.ts +0 -13
- package/dist/src/components/auth/magic-link-button.js +0 -20
- package/dist/src/components/auth/magic-link.d.ts +0 -17
- package/dist/src/components/auth/magic-link.js +0 -37
- package/dist/src/components/auth/provider-buttons.d.ts +0 -19
- package/dist/src/components/auth/provider-buttons.js +0 -35
- package/dist/src/components/auth/reset-password.d.ts +0 -11
- package/dist/src/components/auth/reset-password.js +0 -59
- package/dist/src/components/auth/sign-in.d.ts +0 -14
- package/dist/src/components/auth/sign-in.js +0 -58
- package/dist/src/components/auth/sign-out.d.ts +0 -11
- package/dist/src/components/auth/sign-out.js +0 -34
- package/dist/src/components/auth/sign-up.d.ts +0 -19
- package/dist/src/components/auth/sign-up.js +0 -65
- package/dist/src/components/email/email-changed-email.d.ts +0 -3
- package/dist/src/components/email/email-changed-email.js +0 -23
- package/dist/src/components/email/email-verification-email.d.ts +0 -3
- package/dist/src/components/email/email-verification-email.js +0 -23
- package/dist/src/components/email/magic-link-email.d.ts +0 -3
- package/dist/src/components/email/magic-link-email.js +0 -23
- package/dist/src/components/email/new-device-email.d.ts +0 -3
- package/dist/src/components/email/new-device-email.js +0 -23
- package/dist/src/components/email/otp-email.d.ts +0 -3
- package/dist/src/components/email/otp-email.js +0 -22
- package/dist/src/components/email/password-changed-email.d.ts +0 -3
- package/dist/src/components/email/password-changed-email.js +0 -23
- package/dist/src/components/email/reset-password-email.d.ts +0 -3
- package/dist/src/components/email/reset-password-email.js +0 -23
- package/dist/src/components/settings/account/account-settings.d.ts +0 -13
- package/dist/src/components/settings/account/account-settings.js +0 -19
- package/dist/src/components/settings/account/appearance.d.ts +0 -16
- package/dist/src/components/settings/account/appearance.js +0 -28
- package/dist/src/components/settings/account/change-email.d.ts +0 -15
- package/dist/src/components/settings/account/change-email.js +0 -35
- package/dist/src/components/settings/account/manage-account.d.ts +0 -19
- package/dist/src/components/settings/account/manage-account.js +0 -27
- package/dist/src/components/settings/account/manage-accounts.d.ts +0 -14
- package/dist/src/components/settings/account/manage-accounts.js +0 -27
- package/dist/src/components/settings/account/user-profile.d.ts +0 -13
- package/dist/src/components/settings/account/user-profile.js +0 -29
- package/dist/src/components/settings/security/active-session.d.ts +0 -14
- package/dist/src/components/settings/security/active-session.js +0 -35
- package/dist/src/components/settings/security/active-sessions.d.ts +0 -14
- package/dist/src/components/settings/security/active-sessions.js +0 -29
- package/dist/src/components/settings/security/change-password.d.ts +0 -15
- package/dist/src/components/settings/security/change-password.js +0 -57
- package/dist/src/components/settings/security/linked-account.d.ts +0 -16
- package/dist/src/components/settings/security/linked-account.js +0 -46
- package/dist/src/components/settings/security/linked-accounts.d.ts +0 -15
- package/dist/src/components/settings/security/linked-accounts.js +0 -31
- package/dist/src/components/settings/security/security-settings.d.ts +0 -15
- package/dist/src/components/settings/security/security-settings.js +0 -18
- package/dist/src/components/settings/settings.d.ts +0 -29
- package/dist/src/components/settings/settings.js +0 -39
- package/dist/src/components/user/switch-account-item.d.ts +0 -16
- package/dist/src/components/user/switch-account-item.js +0 -14
- package/dist/src/components/user/switch-account-menu.d.ts +0 -10
- package/dist/src/components/user/switch-account-menu.js +0 -23
- package/dist/src/components/user/user-avatar.d.ts +0 -24
- package/dist/src/components/user/user-avatar.js +0 -31
- package/dist/src/components/user/user-button.d.ts +0 -21
- package/dist/src/components/user/user-button.js +0 -24
- package/dist/src/components/user/user-view.d.ts +0 -21
- package/dist/src/components/user/user-view.js +0 -24
- package/dist/src/core.d.ts +0 -1
- package/dist/src/core.js +0 -1
- package/dist/src/index.d.ts +0 -31
- package/dist/src/index.js +0 -32
- package/dist/src/lib/utils.d.ts +0 -2
- package/dist/src/lib/utils.js +0 -5
- package/dist/src/react-exports.d.ts +0 -1
- 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
|
-
}
|
package/dist/hooks/use-auth.d.ts
DELETED
package/dist/hooks/use-auth.js
DELETED
|
@@ -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
|
-
}
|
package/dist/lib/utils.d.ts
DELETED
package/dist/lib/utils.js
DELETED
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,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;
|