Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Getting 401 with Next JS client side fetching

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 27

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.