| 1 | "use client"; |
| 2 | |
| 3 | import { |
| 4 | createQrCodeSvgData, |
| 5 | getEmailProviderLink, |
| 6 | } from "@better-auth-ui/core"; |
| 7 | import { useAuth } |
| 8 | import type { VariantProps |
| 9 | import { QrCode } |
| 10 | |
| 11 | import { buttonVariants } |
| 12 | import { |
| 13 | Tooltip, |
| 14 | TooltipContent, |
| 15 | TooltipProvider, |
| 16 | TooltipTrigger, |
| 17 | } from "@/components/ui/tooltip"; |
| 18 | import { cn } |
| 19 | |
| 20 | export type OpenEmailButtonProps |
| 21 | /** Email address used to detect the provider, e.g. from the verify-email flow. */ |
| 22 | email: string |
| 23 | className?: string |
| 24 | /** Button variant. Defaults to the primary style for dead-end views where opening the inbox is the only action; pass `"secondary"` where it sits beside a submit button that should stay the primary call to action. */ |
| 25 | variant?: VariantProps |
| 26 | }; |
| 27 | |
| 28 | export function OpenEmailButton({ |
| 29 | email, |
| 30 | className, |
| 31 | variant, |
| 32 | }: OpenEmailButtonProps) |
| 33 | const { localization |
| 34 | |
| 35 | const provider = |
| 36 | const loginUrl = |
| 37 | const qrCode = |
| 38 | |
| 39 | if (!provider || |
| 40 | |
| 41 | const scanLabel = |
| 42 | "{{provider}}", |
| 43 | provider.companyProvider, |
| 44 | ); |
| 45 | |
| 46 | return ( |
| 47 | <TooltipProvider> |
| 48 | <Tooltip> |
| 49 | <TooltipTrigger |
| 50 | type="button" |
| 51 | className={cn(buttonVariants |
| 52 | onClick={() => |
| 53 | window.open(provider |
| 54 | } |
| 55 | > |
| 56 | {localization.auth.openEmailProvider |
| 57 | "{{provider}}", |
| 58 | provider.companyProvider, |
| 59 | )} |
| 60 | <QrCode data-icon=" |
| 61 | </TooltipTrigger> |
| 62 | <TooltipContent |
| 63 | sideOffset={8} |
| 64 | className="flex-col items-center gap-2 p-3" |
| 65 | > |
| 66 | <svg |
| 67 | viewBox={`0 0 ${qrCode |
| 68 | aria-hidden="true" |
| 69 | focusable="false" |
| 70 | className="size-40" |
| 71 | > |
| 72 | <path fill="white |
| 73 | <path fill="black |
| 74 | </svg> |
| 75 | <p className="max-w-40 text-center leading-snug |
| 76 | </TooltipContent> |
| 77 | </Tooltip> |
| 78 | </TooltipProvider> |
| 79 | ); |
| 80 | } |