// app/(defaults)/ebay-settings/EbaySettingsClient.tsx 'use client'; import { useEffect, useMemo, useState } from 'react'; import { useRouter, useSearchParams } from 'next/navigation'; const OAUTH_ENDPOINT = 'https://ebay.backend.data4autos.com/api/ebay/oauth/login'; /** * This expects your backend to redirect back to this page with ?status=success * (or ?connected=1). If your backend uses a different param, adjust below. */ export default function EbaySettingsClient() { const router = useRouter(); const searchParams = useSearchParams(); const [connecting, setConnecting] = useState(false); const [connected, setConnected] = useState(false); const [toast, setToast] = useState(''); // Compute a clean return URL for after OAuth const returnUrl = useMemo(() => { if (typeof window === 'undefined') return ''; // Send user back here after OAuth return `${window.location.origin}/ebay-settings?status=success`; }, []); // On load, detect success flags from query params useEffect(() => { const status = searchParams.get('status'); const connectedFlag = searchParams.get('connected'); if (status === 'success' || connectedFlag === '1') { setConnected(true); setToast('Connection successful'); // Remove query params from the URL after showing success router.replace('/ebay-settings'); } }, [router, searchParams]); const startOauth = () => { try { setConnecting(true); // If your backend supports a return/redirect param, include it: const url = `${OAUTH_ENDPOINT}?return_url=${encodeURIComponent(returnUrl)}`; // Open in the same window window.location.href = url; } catch (e) { setConnecting(false); setToast('Failed to start eBay connection. Please try again.'); } }; return (
{/* Toast / popup */} {toast && (
{toast}
)}

eBay Settings

Connect your eBay store to enable product sync, inventory updates, and order flow.

You’ll be redirected to eBay to authorize access, then returned here automatically.

); }