'Spoof client user agent in Next.js

I have a route that redirects iPhones, but no great way to test it:

export const getServerSideProps = async ({ req }) => {
  const isIphone = req.headers['user-agent'].match(/iPhone/i);

  if (isIphone) {
    return {
      redirect: {
        ...
      }
    }
  }

  return {
    props: {}
  };
}

Is there some way one can spoof the user agent head client side? It seems that changing the navigator.userAgent property does not suffice for whatever fetch function next.js is using under the hood.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source