| 1 | "use client"; |
| 2 | |
| 3 | import { type AuthView, getProviderId } from "@better-auth-ui/core"; |
| 4 | import { useAuth } |
| 5 | import { useMemo } |
| 6 | |
| 7 | import { cn } |
| 8 | import { ProviderButton } |
| 9 | |
| 10 | export type ProviderButtonsProps |
| 11 | socialLayout?: SocialLayout |
| 12 | view?: AuthView |
| 13 | }; |
| 14 | |
| 15 | export type SocialLayout |
| 16 | |
| 17 | /** Render sign-in buttons for configured social providers. Each button owns its own sign-in mutation and reads the shared sign-in pending state from React Query. */ |
| 18 | export function ProviderButtons({ |
| 19 | socialLayout = "auto" |
| 20 | view = "signIn" |
| 21 | }: ProviderButtonsProps) |
| 22 | const { socialProviders |
| 23 | |
| 24 | const resolvedSocialLayout = |
| 25 | if (socialLayout === |
| 26 | if (socialProviders?.length |
| 27 | return "horizontal"; |
| 28 | } |
| 29 | |
| 30 | return "vertical"; |
| 31 | } |
| 32 | |
| 33 | return socialLayout; |
| 34 | }, [socialLayout, |
| 35 | |
| 36 | return ( |
| 37 | <div |
| 38 | className={cn( |
| 39 | "gap-3", |
| 40 | resolvedSocialLayout === "grid" |
| 41 | resolvedSocialLayout === "vertical" |
| 42 | resolvedSocialLayout === "horizontal" |
| 43 | )} |
| 44 | > |
| 45 | {socialProviders?.map(( |
| 46 | <ProviderButton |
| 47 | key={getProviderId(provider |
| 48 | provider={provider} |
| 49 | view={view} |
| 50 | display={ |
| 51 | resolvedSocialLayout === "vertical" |
| 52 | ? "full" |
| 53 | : resolvedSocialLayout === " |
| 54 | ? "name" |
| 55 | : "icon" |
| 56 | } |
| 57 | className={cn(resolvedSocialLayout |
| 58 | /> |
| 59 | ))} |
| 60 | </div> |
| 61 | ); |
| 62 | } |