"use client"; import { Suspense, useEffect, useState } from "react"; import { useRouter, useSearchParams } from "next/navigation"; import Link from "next/link"; import CommonGridShape from "@/components/common/CommonGridShape"; function AuthCallbackContent() { const router = useRouter(); const searchParams = useSearchParams(); const [status, setStatus] = useState("Processing..."); const [error, setError] = useState(null); useEffect(() => { const token = searchParams.get("token"); const errorParam = searchParams.get("error"); const action = searchParams.get("action"); const code = searchParams.get("code"); const state = searchParams.get("state"); // Mirror Callback: If we receive an OAuth code directly from the provider, // proxy it to the backend for processing. if (code && !token) { const provider = searchParams.get("provider") || 'google'; const backendUrl = `${process.env.NEXT_PUBLIC_API_URL}/api/auth/${provider}/callback?${searchParams.toString()}`; window.location.href = backendUrl; return; } if (errorParam) { if (errorParam === 'account_exists_please_login') { setError("This email is already associated with an account. Please sign in with your password and link your social account in settings."); } else if (errorParam === 'account_not_found_please_signup') { setError("Account not found. Please Sign Up to create a new account."); } else if (errorParam === 'authentication_failed') { setError("Authentication failed. Please try again."); } else { setError("An unknown error occurred during authentication."); } setStatus(""); return; } if (token) { if (action === "set_password") { router.push("/auth/set-password?token=" + token); } else { router.push("/dashboard"); } } else { const timeout = setTimeout(() => { setError("No response from server."); setStatus(""); }, 5000); return () => clearTimeout(timeout); } }, [searchParams, router]); return (
{error ? (

Authentication Error

{error}

Back to Sign In
) : (

{status}

)}
{/* Background */}
); } export default function AuthCallback() { return (
}>
); }