Getting 401 with Next JS client side fetching

byytelope
Visitor
1 0 0

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 ()".

Reply 1 (1)

c10s
Shopify Partner
67 12 24

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.