diff --git a/app/page.tsx b/app/page.tsx index 83beff0..b1b971e 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -315,13 +315,27 @@ export default function TwoFactorAuth() { video: { facingMode: "environment" }, }) streamRef.current = stream + if (videoRef.current) { videoRef.current.srcObject = stream - videoRef.current.play() + // Wait for video to be ready before playing + await new Promise((resolve, reject) => { + const video = videoRef.current! + video.onloadedmetadata = () => { + video + .play() + .then(() => resolve()) + .catch(reject) + } + video.onerror = () => reject(new Error("Video load error")) + }) } + setIsCameraOpen(true) - scanQRCode() + // Start scanning after a short delay to ensure video is rendering + setTimeout(() => scanQRCode(), 500) } catch (error) { + console.log("[v0] Camera error:", error) toast({ title: t.cameraFailed, description: t.cameraPermission, @@ -561,6 +575,14 @@ export default function TwoFactorAuth() { } } + const handleAddDialogChange = (open: boolean) => { + if (!open) { + // Stop camera when dialog is closed + stopCamera() + } + setIsAddDialogOpen(open) + } + return (
{/* Header */} @@ -704,7 +726,7 @@ export default function TwoFactorAuth() { />
- +
) : (
-