'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; import { createClient } from '@/lib/supabase/client'; export default function ClientLoginPage() { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); const router = useRouter(); const supabase = createClient(); const handleLogin = async (e: React.FormEvent) => { e.preventDefault(); setError(''); setLoading(true); try { // Call WP auth endpoint const res = await fetch('/api/auth/wp-login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email, password }), }); const data = await res.json(); if (!res.ok) { const errMsg = data.error || `Server error: ${res.status}`; console.error('Login API error:', errMsg, data); setError(errMsg); return; } console.log('Login success, data:', { success: data.success, migrated: data.migrated, legacy: data.legacy, userId: data.user?.id, userEmail: data.user?.email, hasAccessToken: !!data.session?.access_token, }); console.log('Cookies visible to JS now:', document.cookie || '(none)'); console.log('About to redirect to /contributor'); // The wp-login API has already set the supabase session cookie via // its NextResponse. Hard reload so the server re-renders with the // cookie and the browser supabase client picks it up from // document.cookie on page load. window.location.href = '/home-page'; } catch (err: any) { setError(err.message || 'An error occurred'); console.error('Login exception:', err); } finally { setLoading(false); } }; return (

Broadcast Beat

Contributor Portal

{error && (
{error}
)}
setEmail(e.target.value)} required className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-transparent" placeholder="you@example.com" />
setPassword(e.target.value)} required className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-transparent" placeholder="••••••••" />

New contributor?{' '} Register here

); }