fix double response in auth callback + re-query fulfillment service location when null

This commit is contained in:
MOHAN 2026-07-03 00:04:12 +05:30
parent 96dfd467df
commit cceb714a73
2 changed files with 16 additions and 3 deletions

View File

@ -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)}`);

View File

@ -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 ────────────────────────