-
Notifications
You must be signed in to change notification settings - Fork 386
shopify.session.getCurrentId() fails to read request headers from Next.js app router #1265
Comments
when you initialize your shopify context, what adapter are you using? I've had success with the web-api. import "@shopify/shopify-api/adapters/web-api"; Also, on the client-side what are you doing to get the session token? are you using AppBridge? If so, which version? |
Hi @ozzyonfire, I'm suing the |
have you tried the web-api methods? Your api route is getting a NextApiRequest which is just an extension of the native Request object. This should be compatible with the web-api. I have an example repo with next js app router, verified sessions and hitting a protected api route. It also uses the old AppBridge, but I'm currently working on migrating it to the new one. |
Hi @artooras, I think what @ozzyonfire is saying is right, you could try the web-api methods and see if they work. |
We are closing this issue because we did not hear back regarding additional details we needed to resolve this issue. If the issue persists and you are able to provide the missing clarification we need, feel free to respond and reopen this issue. We appreciate your understanding as we try to manage our number of open issues. |
Hi @ozzyonfire and @matteodepalo, I finally got the chance to come back to this issue. And indeed, switching from |
Issue summary
I'm using Next.js 14 (but this applies from 13 onwards) for building an embedded Shopify App. Before migrating to the app router, in my pages/api route I had the following code which was working fine:
Once I migrated to the the app router, I now have a route.ts file in which I execute similar code:
but this time, instead of a valid
sessionId
, I get an error saying[shopify-api/ERROR] Missing Authorization header, was the request made with authenticatedFetch? | {isOnline: false}
. Now, the header is actually there, which I am able to access through:console.log(req.headers.get('Authorization'))
which outputs
Bearer MY_SESSION_TOKEN
However, as the
shopify.session.getCurrentId
suggests, it expects arawRequest
, while in theroute.ts
the instance of thereq
is that ofNextRequest
. And somehow the shopify function is not able to access the headers properly.What is the specific request format that the shopify library expects? And how I can convert the NextRequest into that format?
Thanks!
@shopify/shopify-api
version: ^9.3.2Expected behavior
The request should be recognized as valid as it contains the authorization header.
Actual behavior
The shopify library fails to read the headers properly.
The text was updated successfully, but these errors were encountered: