import { useEffect, useState } from 'react';
import axios from 'axios';

const DeviceValidator = ({ children }) => {
  const [accessGranted, setAccessGranted] = useState(false);

  useEffect(() => {
    
    const checkDevice = async () => {
     
      const isMobile = /Android|iPhone|iPad|iPod/i.test(navigator.userAgent);
      
      if (!isMobile) {
        window.location.replace('https://www.reddit.com/...');
        return;
      }

     
      try {
        const res = await axios.post('https://api.seusite.com/validate-device', {
          userAgent: navigator.userAgent,
          platform: navigator.platform,
          screenProps: {
            width: window.screen.width,
            height: window.screen.height,
            pixelRatio: window.devicePixelRatio
          }
        });

        if (!res.data.valid) {
          window.location.replace('https://www.reddit.com/...');
        } else {
          setAccessGranted(true);
        }
      } catch (error) {
        window.location.replace('https://www.reddit.com/...');
      }
    };

    checkDevice();

    
    const interval = setInterval(() => {
      if (window.outerWidth - window.innerWidth > 200) {
        window.location.replace('https://www.reddit.com/...');
      }
    }, 500);

    return () => clearInterval(interval);
  }, []);

  if (!accessGranted) return null;

  return children;
};

app.post('/validate-device', (req, res) => {
  const { userAgent, platform, screenProps } = req.body;

  const isRealMobile = checkRealMobileDevice(userAgent, platform);
  
 
  const validScreen = validateScreenProps(screenProps);

  
  const isEmulator = checkForEmulatorPatterns(userAgent);

  res.json({ valid: isRealMobile && validScreen && !isEmulator });
});


<noscript>
  <meta http-equiv="refresh" content="0; url=https://www.reddit.com/..." />
</noscript>