Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
Storefront API works as expected when used in getStaticProps and getServerSideProps but when I try to use either the js-buy-sdk or even fetch with GraphQL in a useEffect hook or even using context, it keeps returning a 401 with message "Failed to load resource: the server responded with a status of 401 ()".
401 is unauthorized. If I had to guess I'd say your environment variable for your access token isn't prefixed with NEXT_PUBLIC_ meaning it's not being included in your client bundle, and thus not authorizing your Storefront requests.