"use client"; import { AnimatePresence, motion } from "framer-motion"; import { Loader2 } from "lucide-react"; import { useSearchParams } from "next/navigation"; import { Suspense, useEffect, useState } from "react"; import { toast } from "sonner"; import { Logo } from "@/components/Logo"; import { getAuthErrorDetails, shouldRetry } from "@/lib/auth-errors"; import { AmbientBackground } from "./AmbientBackground"; import { GoogleLoginButton } from "./GoogleLoginButton"; import { LocalLoginForm } from "./LocalLoginForm"; function LoginContent() { const [authType, setAuthType] = useState(null); const [isLoading, setIsLoading] = useState(true); const [urlError, setUrlError] = useState<{ title: string; message: string } | null>(null); const searchParams = useSearchParams(); useEffect(() => { // Check for various URL parameters that might indicate success or error states const registered = searchParams.get("registered"); const error = searchParams.get("error"); const message = searchParams.get("message"); const logout = searchParams.get("logout"); // Show registration success message if (registered === "true") { toast.success("Registration successful!", { description: "You can now sign in with your credentials", duration: 5000, }); } // Show logout confirmation if (logout === "true") { toast.success("Logged out successfully", { description: "You have been securely logged out", duration: 3000, }); } // Show error messages from OAuth or other flows using auth-errors utility if (error) { // Use the auth-errors utility to get proper error details const errorDetails = getAuthErrorDetails(error); // If we have a custom message from URL params, use it as description const errorDescription = message ? decodeURIComponent(message) : errorDetails.description; // Set persistent error display setUrlError({ title: errorDetails.title, message: errorDescription, }); // Show toast with conditional retry action const toastOptions: any = { description: errorDescription, duration: 6000, }; // Add retry action if the error is retryable if (shouldRetry(error)) { toastOptions.action = { label: "Retry", onClick: () => window.location.reload(), }; } toast.error(errorDetails.title, toastOptions); } // Show general messages if (message && !error && !registered && !logout) { toast.info("Notice", { description: decodeURIComponent(message), duration: 4000, }); } // Get the auth type from environment variables setAuthType(process.env.NEXT_PUBLIC_FASTAPI_BACKEND_AUTH_TYPE || "GOOGLE"); setIsLoading(false); }, [searchParams]); // Show loading state while determining auth type if (isLoading) { return (
Loading...
); } if (authType === "GOOGLE") { return ; } return (

Sign In

{/* URL Error Display */} {urlError && (
Error Icon

{urlError.title}

{urlError.message}

)}
); } // Loading fallback for Suspense const LoadingFallback = () => (
Loading...
); export default function LoginPage() { return ( }> ); }