Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added bun.lockb
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just need to delete this bun file or put in in gitignore

Binary file not shown.
87 changes: 62 additions & 25 deletions docs/content/docs/components/change-email-card.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,30 @@ title: <ChangeEmailCard />

The `<ChangeEmailCard />` component provides a simple and secure UI that allows users to change their account email address, including verification emails sent to the updated address, if email verification is enabled.

<img alt="Change Email Card" src="/screenshots/change-email-card-dark.png" className="rounded-xl hidden dark:block w-lg mt-0 mb-0" />
<img alt="Change Email Card" src="/screenshots/change-email-card-light.png" className="rounded-xl dark:hidden w-lg mt-0 mb-0" />
<img
alt="Change Email Card"
src="/screenshots/change-email-card-dark.png"
className="rounded-xl hidden dark:block w-lg mt-0 mb-0"
/>
<img
alt="Change Email Card"
src="/screenshots/change-email-card-light.png"
className="rounded-xl dark:hidden w-lg mt-0 mb-0"
/>

## Usage

Here's how to implement `<ChangeEmailCard />` on your custom settings page:

```tsx
import { ChangeEmailCard } from "@daveyplate/better-auth-ui"
import { ChangeEmailCard } from "@daveyplate/better-auth-ui";

export default function SettingsPage() {
return (
<div className="flex flex-col gap-6">
<ChangeEmailCard />
</div>
)
return (
<div className="flex flex-col gap-6">
<ChangeEmailCard />
</div>
);
}
```

Expand All @@ -37,15 +45,15 @@ You can customize the styles using the provided `classNames` prop:

```tsx
<ChangeEmailCard
classNames={{
base: "border-primary shadow",
header: "bg-primary-foreground text-primary",
title: "text-xl font-semibold",
description: "text-muted-foreground",
content: "bg-background",
footer: "bg-muted",
input: "bg-transparent border-primary placeholder:text-muted-foreground"
}}
classNames={{
base: "border-primary shadow",
header: "bg-primary-foreground text-primary",
title: "text-xl font-semibold",
description: "text-muted-foreground",
content: "bg-background",
footer: "bg-muted",
input: "bg-transparent border-primary placeholder:text-muted-foreground",
}}
/>
```

Expand All @@ -55,12 +63,41 @@ You can pass custom text via the `localization` prop:

```tsx
<ChangeEmailCard
localization={{
EMAIL: "Your Email",
EMAIL_DESCRIPTION: "You can update your email here.",
EMAIL_INSTRUCTIONS: "We'll send you a verification link to your new email address.",
EMAIL_PLACEHOLDER: "[email protected]",
EMAIL_VERIFY_CHANGE: "Check your inbox for the verification link!"
}}
localization={{
EMAIL: "Your Email",
EMAIL_DESCRIPTION: "You can update your email here.",
EMAIL_INSTRUCTIONS: "We'll send you a verification link to your new email address.",
EMAIL_PLACEHOLDER: "[email protected]",
EMAIL_VERIFY_CHANGE: "Check your inbox for the verification link!",
}}
/>
```
```

## Callbacks

The `onSave` prop allows you to execute custom logic after a successful email change or verification email resend:

```tsx
// Basic usage
<ChangeEmailCard
onSave={() => {
console.log("Email updated successfully");
}}
/>;

// Using with a dialog
function EmailChangeDialog({ open, onOpenChange }) {
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent>
<ChangeEmailCard
onSave={() => {
// Close the dialog after successful update
onOpenChange(false);
}}
/>
</DialogContent>
</Dialog>
);
}
```
97 changes: 68 additions & 29 deletions docs/content/docs/components/change-password-card.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,30 @@ title: <ChangePasswordCard />

The `<ChangePasswordCard />` provides a secure and user-friendly interface for users to update their account passwords, seamlessly integrated with your authentication flow. It supports verification workflows to ensure passwords are securely updated, revoking other active sessions when the password changes.

<img alt="Change Password Card" src="/screenshots/change-password-card-dark.png" className="rounded-xl hidden dark:block w-lg mt-0 mb-0" />
<img alt="Change Password Card" src="/screenshots/change-password-card-light.png" className="rounded-xl dark:hidden w-lg mt-0 mb-0" />
<img
alt="Change Password Card"
src="/screenshots/change-password-card-dark.png"
className="rounded-xl hidden dark:block w-lg mt-0 mb-0"
/>
<img
alt="Change Password Card"
src="/screenshots/change-password-card-light.png"
className="rounded-xl dark:hidden w-lg mt-0 mb-0"
/>

## Usage

Here's how you can include `<ChangePasswordCard />` in your user account settings page:

```tsx
import { ChangePasswordCard } from "@daveyplate/better-auth-ui"
import { ChangePasswordCard } from "@daveyplate/better-auth-ui";

export default function SettingsPage() {
return (
<div className="flex flex-col gap-6">
<ChangePasswordCard />
</div>
)
return (
<div className="flex flex-col gap-6">
<ChangePasswordCard />
</div>
);
}
```

Expand All @@ -37,16 +45,16 @@ Customize the component styles extensively by providing Tailwind CSS utility cla

```tsx
<ChangePasswordCard
classNames={{
base: "border-primary shadow",
header: "bg-primary-foreground",
title: "text-primary font-semibold text-xl",
description: "text-muted-foreground",
content: "bg-background",
footer: "bg-muted",
input: "bg-background placeholder:text-muted-foreground",
button: "bg-primary hover:bg-primary-foreground text-white"
}}
classNames={{
base: "border-primary shadow",
header: "bg-primary-foreground",
title: "text-primary font-semibold text-xl",
description: "text-muted-foreground",
content: "bg-background",
footer: "bg-muted",
input: "bg-background placeholder:text-muted-foreground",
button: "bg-primary hover:bg-primary-foreground text-white",
}}
/>
```

Expand All @@ -64,15 +72,46 @@ You can easily adjust the displayed texts via the localization prop:

```tsx
<ChangePasswordCard
localization={{
CHANGE_PASSWORD: "Update your password",
CHANGE_PASSWORD_DESCRIPTION: "Set a new password for your account",
CURRENT_PASSWORD: "Current Password",
NEW_PASSWORD: "New Password",
CHANGE_PASSWORD_SUCCESS: "Password successfully updated!",
SET_PASSWORD: "Set Password",
SET_PASSWORD_DESCRIPTION: "Add a password to your social account for easy future logins.",
SET_PASSWORD_EMAIL_SENT: "Check your mailbox to set your new password!"
}}
localization={{
CHANGE_PASSWORD: "Update your password",
CHANGE_PASSWORD_DESCRIPTION: "Set a new password for your account",
CURRENT_PASSWORD: "Current Password",
NEW_PASSWORD: "New Password",
CHANGE_PASSWORD_SUCCESS: "Password successfully updated!",
SET_PASSWORD: "Set Password",
SET_PASSWORD_DESCRIPTION: "Add a password to your social account for easy future logins.",
SET_PASSWORD_EMAIL_SENT: "Check your mailbox to set your new password!",
}}
/>
```
```

## Callbacks

The `onSave` prop allows you to execute custom logic after a successful password change or set password email sent:

```tsx
// Basic usage
<ChangePasswordCard
onSave={() => {
console.log("Password updated successfully");
}}
/>;

// Using with a dialog
function PasswordChangeDialog({ open, onOpenChange }) {
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent>
<ChangePasswordCard
onSave={() => {
// Close dialog after successful password update
onOpenChange(false);
// Optionally redirect to security settings
router.push("/settings/security");
}}
/>
</DialogContent>
</Dialog>
);
}
```
63 changes: 47 additions & 16 deletions docs/content/docs/components/update-username-card.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ The `<UpdateUsernameCard />` component provides a simple, intuitive UI that enab
Include the `<UpdateUsernameCard />` in your custom settings or profile page:

```tsx
import { UpdateUsernameCard } from "@daveyplate/better-auth-ui"
import { UpdateUsernameCard } from "@daveyplate/better-auth-ui";

export default function CustomSettings() {
return (
<div className="flex flex-col gap-6">
<UpdateUsernameCard />
</div>
)
return (
<div className="flex flex-col gap-6">
<UpdateUsernameCard />
</div>
);
}
```

Expand All @@ -32,14 +32,45 @@ The styles can be customized precisely with Tailwind classes via the `classNames

```tsx
<UpdateUsernameCard
classNames={{
base: "border-blue-500",
header: "bg-blue-50",
title: "text-blue-500",
description: "text-muted-foreground",
content: "bg-blue-50",
footer: "bg-blue-50",
input: "bg-background border-blue-500 placeholder:text-muted",
}}
classNames={{
base: "border-blue-500",
header: "bg-blue-50",
title: "text-blue-500",
description: "text-muted-foreground",
content: "bg-blue-50",
footer: "bg-blue-50",
input: "bg-background border-blue-500 placeholder:text-muted",
}}
/>
```
```

## Callbacks

The `onSave` prop allows you to execute custom logic after a successful username update:

```tsx
// Basic usage
<UpdateUsernameCard
onSave={() => {
console.log("Username updated successfully");
}}
/>;

// Using with a dialog
function UsernameUpdateDialog({ open, onOpenChange }) {
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent>
<UpdateUsernameCard
onSave={() => {
// Close dialog after successful update
onOpenChange(false);
// Optionally refresh user profile
refreshUserProfile();
}}
/>
</DialogContent>
</Dialog>
);
}
```
8 changes: 6 additions & 2 deletions src/components/settings/account/update-field-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export interface UpdateFieldCardProps {
label?: ReactNode
type?: FieldType
value?: unknown
validate?: (value: string) => boolean | Promise<boolean>
validate?: (value: string) => boolean | Promise<boolean>,
onSave?: () => void
}

export function UpdateFieldCard({
Expand All @@ -53,7 +54,8 @@ export function UpdateFieldCard({
label,
type,
value,
validate
validate,
onSave
}: UpdateFieldCardProps) {
const {
hooks: { useSession },
Expand Down Expand Up @@ -148,6 +150,8 @@ export function UpdateFieldCard({
message: getLocalizedError({ error, localization })
})
}

onSave?.()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this onSave should be called inside the try block? Since after catching the error would be a failure

}

return (
Expand Down
2 changes: 2 additions & 0 deletions src/components/settings/account/update-name-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export function UpdateNameCard({
className,
classNames,
localization,
onSave,
...props
}: SettingsCardProps) {
const {
Expand All @@ -33,6 +34,7 @@ export function UpdateNameCard({
localization={localization}
placeholder={localization.NAME_PLACEHOLDER}
required={nameRequired}
onSave={onSave}
{...props}
/>
)
Expand Down
Loading