From 48f4669a083f155f6f0c21e0026b8018eeeba8a9 Mon Sep 17 00:00:00 2001 From: Mohammad Cheikh Date: Wed, 18 Dec 2024 18:49:31 -0500 Subject: [PATCH] change to more robust mobile check --- examples/react-components/src/app/page.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/react-components/src/app/page.tsx b/examples/react-components/src/app/page.tsx index b0fb9e0c..a0d46d15 100644 --- a/examples/react-components/src/app/page.tsx +++ b/examples/react-components/src/app/page.tsx @@ -71,14 +71,20 @@ export default function AuthPage() { useEffect(() => { const checkMobile = () => { - setIsMobile(window.innerWidth <= 768); - setShowContent(window.innerWidth > 768); + const userAgent = navigator.userAgent || navigator.vendor || window.opera; + const mobileRegex = + /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i; + setIsMobile(mobileRegex.test(userAgent.toLowerCase())); }; checkMobile(); window.addEventListener("resize", checkMobile); return () => window.removeEventListener("resize", checkMobile); }, []); - + useEffect(() => { + if (isMobile) { + setShowContent(false); + } + }, [isMobile]); useEffect(() => { const manageSession = async () => { if (turnkey) {