Webhook authentication returns admin undefined

nicofrm
Shopify Partner
4 0 2

Hi all,

 

the admin and session context is undefined when authenticating Webhooks like the following:

 

 

  const { topic, shop, admin, session, payload } = await authenticate.webhook(
    request
  );

 

 

The webhooks fail when I test it via the CLI. However, when registering the app with npm run shopify app dev -- --reset , the APP_UNINSTALLED Webhook fires and works fine (admin and session is not undefined). 

 

I register the webhooks in the shopify.server.js file like this:

 

 

webhooks: {
    APP_UNINSTALLED: {
      deliveryMethod: DeliveryMethod.Http,
      callbackUrl: "https://b818-2a01-c23-8422-5300-1c6-e7a8-44df-50ed.ngrok-free.app/webhooks",
      callback: async () => {
        console.log("webhook registered")
      },
    },
    CUSTOMERS_DATA_REQUEST: {
      deliveryMethod: DeliveryMethod.Http,
      callbackUrl: "https://b818-2a01-c23-8422-5300-1c6-e7a8-44df-50ed.ngrok-free.app/webhooks",
    },
    CUSTOMERS_REDACT: {
      deliveryMethod: DeliveryMethod.Http,
      callbackUrl: "https://b818-2a01-c23-8422-5300-1c6-e7a8-44df-50ed.ngrok-free.app/webhooks",
    },
    SHOP_REDACT: {
      deliveryMethod: DeliveryMethod.Http,
      callbackUrl: "https://b818-2a01-c23-8422-5300-1c6-e7a8-44df-50ed.ngrok-free.app/webhooks",
    },
  },
  hooks: {
    afterAuth: async ({ session }) => {
      shopify.registerWebhooks({ session });
    },
  },
  future: {
    v3_webhookAdminContext: true,
    v3_authenticatePublic: true,
  },

 

 

The app should be installed in my store, as I can use it without an issue.

 

Any help is greatly appreciated!

Reply 1 (1)

soft-blockk
Shopify Partner
1 0 0

If Shopify send a real webhook request then admin won't show as undefined, but if you are testing locally then it will be undefined