"use client"; import { useState, useEffect } from "react"; import { auth } from "@/lib/firebase/config"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; export default function TestAuthPage() { const [results, setResults] = useState(null); const [loading, setLoading] = useState(false); const runDiagnostics = async () => { setLoading(true); try { const user = auth.currentUser; if (!user) { setResults({ error: "Not authenticated. Please sign in first." }); return; } const token = await user.getIdToken(); // Test with token const response = await fetch('/api/diagnose', { headers: { 'Authorization': `Bearer ${token}`, }, }); const data = await response.json(); setResults({ ...data, clientInfo: { uid: user.uid, email: user.email, tokenLength: token.length, } }); } catch (error: any) { setResults({ error: error.message }); } finally { setLoading(false); } }; useEffect(() => { const unsubscribe = auth.onAuthStateChanged((user) => { console.log('[Test Auth] Auth state changed:', user ? user.uid : 'No user'); if (user) { runDiagnostics(); } else { setResults({ error: "Not authenticated. Please sign in first.", note: "Redirecting to auth page...", }); // Redirect to auth page after a delay setTimeout(() => { window.location.href = '/auth'; }, 2000); } }); return () => unsubscribe(); }, []); return (

Auth Diagnostics

Testing Firebase authentication and token verification

Diagnostic Results {loading &&

Running diagnostics...

} {results && (
                {JSON.stringify(results, null, 2)}
              
)} {!loading && !results && (

Click "Run Diagnostics" to test

)}
); }