fix(auth): prefer fulfillsOnlineOrders location over first app location
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
09cf21243f
commit
2ab720fc4a
6
auth.js
6
auth.js
@ -52,10 +52,12 @@ router.get("/auth/callback", async (req, res) => {
|
||||
try {
|
||||
const locResp = await axios.post(
|
||||
`https://${shop}/admin/api/${process.env.SHOPIFY_API_VERSION || "2025-10"}/graphql.json`,
|
||||
{ query: "{ locations(first: 1) { nodes { id name } } }" },
|
||||
{ query: '{ locations(first: 10, includeInactive: false) { nodes { id name fulfillsOnlineOrders } } }' },
|
||||
{ headers: { "X-Shopify-Access-Token": access_token, "Content-Type": "application/json" } }
|
||||
);
|
||||
const node = locResp.data?.data?.locations?.nodes?.[0];
|
||||
const nodes = locResp.data?.data?.locations?.nodes || [];
|
||||
// Prefer the location that fulfills online orders (the real shop location)
|
||||
const node = nodes.find((l) => l.fulfillsOnlineOrders) || nodes[0];
|
||||
if (node?.id) {
|
||||
saveToken(shop, access_token, scope, null, node.id);
|
||||
log(shop, `Primary location saved: ${node.name} (${node.id})`);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user