import React, { useState, useEffect } from 'react'; import { useAuth } from '../contexts/AuthContext'; const DebugInfo: React.FC = () => { const { user } = useAuth(); const [debugInfo, setDebugInfo] = useState(null); const [cameraSupported, setCameraSupported] = useState(null); useEffect(() => { // Check camera support setCameraSupported( navigator.mediaDevices && navigator.mediaDevices.getUserMedia && typeof navigator.mediaDevices.getUserMedia === 'function' ); // Test API connectivity testAPIs(); }, [user]); const testAPIs = async () => { const token = localStorage.getItem('token'); const results: any = { token: token ? `${token.substring(0, 20)}...` : 'No token', tokenLength: token?.length || 0, user: user ? { id: user.id, username: user.username, roles: user.roles } : 'Not logged in' }; try { // Test collections API const collectionsResponse = await fetch('/api/collections', { headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' } }); results.collectionsAPI = { status: collectionsResponse.status, ok: collectionsResponse.ok, data: collectionsResponse.ok ? await collectionsResponse.json() : await collectionsResponse.text() }; } catch (error: any) { results.collectionsAPI = { error: error.message }; } setDebugInfo(results); }; const testCamera = async () => { try { const stream = await navigator.mediaDevices.getUserMedia({ video: { facingMode: 'environment' } }); setDebugInfo((prev: any) => ({ ...prev, cameraTest: '✅ Camera access successful', cameraStream: { active: stream.active, tracks: stream.getVideoTracks().length } })); // Stop the test stream stream.getTracks().forEach(track => track.stop()); } catch (error: any) { setDebugInfo((prev: any) => ({ ...prev, cameraTest: `❌ Camera error: ${error.message}`, cameraError: error.name })); } }; if (!debugInfo) return
Loading debug info...
; return (

🔧 Debug Information

Camera Support: {cameraSupported ? '✅ Supported' : '❌ Not supported'}
User: {JSON.stringify(debugInfo.user, null, 2)}
Token: {debugInfo.token} (Length: {debugInfo.tokenLength})
Collections API:
            {JSON.stringify(debugInfo.collectionsAPI, null, 2)}
          
{debugInfo.cameraTest && (
Camera Test: {debugInfo.cameraTest} {debugInfo.cameraStream && (
Active: {debugInfo.cameraStream.active ? 'Yes' : 'No'}, Tracks: {debugInfo.cameraStream.tracks}
)} {debugInfo.cameraError && (
Error Type: {debugInfo.cameraError}
)}
)}
); }; export default DebugInfo;