diff --git a/src/components/DebugInfo.tsx b/src/components/DebugInfo.tsx new file mode 100644 index 0000000..4c8cf2e --- /dev/null +++ b/src/components/DebugInfo.tsx @@ -0,0 +1,144 @@ +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; \ No newline at end of file diff --git a/src/pages/Scanner.tsx b/src/pages/Scanner.tsx index e73ef03..dfe7f36 100644 --- a/src/pages/Scanner.tsx +++ b/src/pages/Scanner.tsx @@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react'; import CameraScanner from '../components/CameraScanner'; import GlowingCard from '../components/GlowingCard'; import CardImageDisplay from '../components/CardImageDisplay'; +import DebugInfo from '../components/DebugInfo'; import { cardMatcher } from '../services/cardMatcher'; import { useAuth } from '../contexts/AuthContext'; @@ -275,6 +276,9 @@ const Scanner: React.FC = () => {

+ {/* Debug Information */} + + {/* Error Display */} {error && (