"use client"; import { useState, FormEvent } from "react"; import { useRouter } from "next/navigation"; import { signIn } from "next-auth/react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Alert, AlertDescription } from "@/components/ui/alert"; interface LinkAccountClientProps { provider: string; email: string; linkingId: string; } export default function LinkAccountClient({ provider, email, linkingId }: LinkAccountClientProps) { const router = useRouter(); const [password, setPassword] = useState(""); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); const handleLinkAccount = async (event: FormEvent) => { event.preventDefault(); setError(null); setLoading(true); try { const response = await fetch("/api/auth/link-account", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ linkingId, password }) }); const data = await response.json(); if (!response.ok) { setError(data.error || "Failed to link account"); setLoading(false); return; } await signIn(provider, { callbackUrl: "/" }); } catch { setError("An error occurred while linking your account"); setLoading(false); } }; const handleUsePassword = () => { router.push("/login"); }; const providerName = provider.charAt(0).toUpperCase() + provider.slice(1); return (
Link Your Account An account with {email} already exists

Would you like to link your {providerName} account to your existing account? Enter your password to confirm.

{error && ( {error} )}
setPassword(e.target.value)} required autoComplete="current-password" autoFocus disabled={loading} />
); }