| 1 | "use client"; |
| 2 | |
| 3 | import { useAuth } from |
| 4 | import type { ComponentProps |
| 5 | |
| 6 | import { cn } |
| 7 | import { ChangeEmail } |
| 8 | import { EmailAddresses } |
| 9 | import { UserProfile } |
| 10 | |
| 11 | export type AccountSettingsProps |
| 12 | className?: string |
| 13 | }; |
| 14 | |
| 15 | /** |
| 16 | * Renders the account settings layout. |
| 17 | * |
| 18 | * Uses `emailAndPassword` and `plugins` from `useAuth()` to conditionally show sections: |
| 19 | * - `UserProfile` always renders. |
| 20 | * - The change-email card renders when `emailAndPassword?.enabled` is truthy |
| 21 | * or the `magicLink` plugin is registered, and a plugin may replace it via `cardOverrides.account.changeEmail` (the email-OTP plugin swaps in its code-based flow). |
| 22 | * - Plugin-contributed account cards are rendered via the plugins array |
| 23 | * (e.g. `Appearance` from the theme plugin, multi-session accounts). |
| 24 | */ |
| 25 | export function AccountSettings({ |
| 26 | className, |
| 27 | ...props |
| 28 | }: AccountSettingsProps |
| 29 | const { emailAndPassword, |
| 30 | |
| 31 | const hasMagicLink = |
| 32 | |
| 33 | const ChangeEmailOverride = |
| 34 | (plugin) => |
| 35 | )?.cardOverrides?.account?. |
| 36 | const ChangeEmailCard = |
| 37 | |
| 38 | // A plugin that replaces the card brings its own way to confirm the change, so it can stand on its own without password or magic-link auth. |
| 39 | const showChangeEmail = |
| 40 | emailAndPassword?.enabled || |
| 41 | |
| 42 | return ( |
| 43 | <div |
| 44 | className={cn(" |
| 45 | {...props} |
| 46 | > |
| 47 | <UserProfile /> |
| 48 | {showChangeEmail && <ChangeEmailCard |
| 49 | <EmailAddresses /> |
| 50 | {plugins.flatMap( |
| 51 | (plugin) => |
| 52 | plugin.accountCards?.map |
| 53 | <Card key={ |
| 54 | )) ?? [], |
| 55 | )} |
| 56 | </div> |
| 57 | ); |
| 58 | } |