import { useEffect } from 'react'; import { useSearchParams, useNavigate } from 'react-router-dom'; import { useVercelOAuth } from '@/hooks/useVercelOAuth'; import { useDeploySettings } from '@/hooks/useDeploySettings'; import { useToast } from '@/hooks/useToast'; import { Card, CardContent } from '@/components/ui/card'; export default function VercelOAuth() { const [searchParams] = useSearchParams(); const navigate = useNavigate(); const { handleCallback } = useVercelOAuth(); const { isInitialized } = useDeploySettings(); const { toast } = useToast(); useEffect(() => { // Wait for deploy settings to be initialized if (!isInitialized) { return; } const code = searchParams.get('code'); const state = searchParams.get('state'); const error = searchParams.get('error'); const errorDescription = searchParams.get('error_description'); const storedState = localStorage.getItem('vercel_oauth_state'); // Handle OAuth errors if (error) { toast({ title: "Vercel OAuth Error", description: errorDescription || error, variant: "destructive", }); navigate('/settings/deploy'); return; } // Handle successful OAuth callback if (code && state && storedState) { handleCallback(code, state).then((success) => { if (success) { toast({ title: "Vercel Connected", description: "Successfully connected to Vercel. You can now deploy your projects.", }); } else { toast({ title: "Connection Failed", description: "Failed to connect to Vercel. Please try again.", variant: "destructive", }); } // Always redirect to Deploy settings after handling the callback navigate('/settings/deploy'); }); } else { // No code or state parameters - redirect to Deploy settings navigate('/settings/deploy'); } }, [searchParams, handleCallback, toast, navigate, isInitialized]); return (

Connecting to Vercel

Processing your Vercel authentication...

); }