Magic Link
better-auth-ui/magic-linkFreeComponent
Magic-link plugin: passwordless email sign-in form, toggle button between password and magic-link routes, and the AuthPlugin scaffolding that registers the view with `<Auth>`.
Live preview
live · rendered by the registry
Rendered by better-auth-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://better-auth-ui.com/r/magic-link.jsonSource
1"use client"23import { authMutationKeys } from "@better-auth-ui/core"4import {5 type MagicLinkAuthClient,6 useAuth,7 useAuthPlugin,8 useSignInMagicLink9} from "@better-auth-ui/react"10import { useIsMutating } from "@tanstack/react-query"11import { type SyntheticEvent, useState } from "react"1213import { Button } from "@/components/ui/button"14import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"15import {16 Field,17 FieldDescription,18 FieldError,19 FieldGroup,20 FieldLabel,21 FieldSeparator22} from "@/components/ui/field"23import { Input } from "@/components/ui/input"24import { Spinner } from "@/components/ui/spinner"25import { magicLinkPlugin } from "@/lib/auth/magic-link-plugin"26import { cn } from "@/lib/utils"27import { MAGIC_LINK_SENT_STORAGE_KEY } from "./magic-link-sent"28import { ProviderButtons, type SocialLayout } from "./provider-buttons"2930export type MagicLinkProps = {31 className?: string32 socialLayout?: SocialLayout33 socialPosition?: "top" | "bottom"34}3536/**37 * Render a card-based sign-in form that sends an email magic link and optionally shows social provider buttons.38 *39 * @param className - Additional CSS class names applied to the card container40 * @param socialLayout - Layout style for social provider buttons41 * @param socialPosition - Position of social provider buttons; `"top"` or `"bottom"`. Defaults to `"bottom"`.42 * @returns The magic-link sign-in UI as a JSX element43 */44export function MagicLink({45 className,46 socialLayout,47 socialPosition = "bottom"48}: MagicLinkProps) {49 const {50 authClient,51 basePaths,52 baseURL,53 emailAndPassword,54 localization,55 navigate,56 plugins,57 redirectTo,58 socialProviders,59 viewPaths,60 Link61 } = useAuth()62 const { localization: magicLinkLocalization, viewPaths: magicLinkViewPaths } =63 useAuthPlugin(magicLinkPlugin)6465 const [email, setEmail] = useState("")6667 const { mutate: signInMagicLink, isPending: signInMagicLinkPending } =68 useSignInMagicLink(authClient as MagicLinkAuthClient, {69 onSuccess: (_data, variables) => {70 sessionStorage.setItem(MAGIC_LINK_SENT_STORAGE_KEY, variables.email)71 navigate({72 to: `${basePaths.auth}/${magicLinkViewPaths.auth.magicLinkSent}`73 })74 }75 })7677 const signInMutating = useIsMutating({78 mutationKey: authMutationKeys.signIn.all79 })80 const signUpMutating = useIsMutating({81 mutationKey: authMutationKeys.signUp.all82 })83// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from better-auth-ui
All 49 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Account Settingsaccount-settings | better-auth-ui | Components | Free | 2 deps | |
| Active Sessionsactive-sessions | better-auth-ui | Components | Free | 5 deps · 2 files | |
| Additional Fieldadditional-field | better-auth-ui | Components | Free | 5 deps | |
| Adminadmin | better-auth-ui | Components | Free | 4 deps · 3 files | |
| Anonymousanonymous | better-auth-ui | Components | Free | 4 deps · 3 files | |
| API Keyapi-key | better-auth-ui | Components | Free | 4 deps · 10 files | |
| Authauth | better-auth-ui | Components | Free | 2 deps | |
| Auth Providerauth-provider | better-auth-ui | Components | Free | 4 deps · 2 files |
