fix double response in auth callback + re-query fulfillment service location when null
This commit is contained in:
parent
96dfd467df
commit
cceb714a73
2
auth.js
2
auth.js
@ -137,8 +137,6 @@ router.get('/auth/callback', async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
res.redirect(`https://admin.shopify.com`);
|
res.redirect(`https://admin.shopify.com`);
|
||||||
|
|
||||||
res.send('Access token saved. You may close this window.');
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errMsg = err.response?.data || err.message;
|
const errMsg = err.response?.data || err.message;
|
||||||
log(shop, `❌ OAuth error: ${JSON.stringify(errMsg)}`);
|
log(shop, `❌ OAuth error: ${JSON.stringify(errMsg)}`);
|
||||||
|
|||||||
@ -66,7 +66,22 @@ async function createFulfillmentService(shop, accessToken) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The fulfillment service has its own Shopify-managed location — use it as fallback
|
// The fulfillment service has its own Shopify-managed location — use it as fallback
|
||||||
const serviceFallbackLocationId = fulfillmentService?.location?.id || null;
|
// Shopify sometimes returns location: null from the create mutation — re-query if so
|
||||||
|
let serviceFallbackLocationId = fulfillmentService?.location?.id || null;
|
||||||
|
if (!serviceFallbackLocationId) {
|
||||||
|
try {
|
||||||
|
log(shop, `🔍 [FulfillmentService] location null from mutation — re-querying fulfillment services...`);
|
||||||
|
const reQueryResp = await client.post('', {
|
||||||
|
query: `query { fulfillmentServices(type: THIRD_PARTY) { id handle location { id name } } }`,
|
||||||
|
});
|
||||||
|
const svcs = reQueryResp.data?.data?.fulfillmentServices || [];
|
||||||
|
const matched = svcs.find(s => s.handle === 'data4autos-distribution') || svcs[0] || null;
|
||||||
|
serviceFallbackLocationId = matched?.location?.id || null;
|
||||||
|
log(shop, `📍 [FulfillmentService] Re-query location: ${serviceFallbackLocationId}`);
|
||||||
|
} catch (reQErr) {
|
||||||
|
log(shop, `⚠️ [FulfillmentService] Re-query failed: ${reQErr.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
log(shop, `📍 [FulfillmentService] Service location (fallback): ${serviceFallbackLocationId}`);
|
log(shop, `📍 [FulfillmentService] Service location (fallback): ${serviceFallbackLocationId}`);
|
||||||
|
|
||||||
// ── Step 2: Try to create a custom named location ────────────────────────
|
// ── Step 2: Try to create a custom named location ────────────────────────
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user