Webhook authentication returns admin undefined

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!

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

Hey, were you able to solve this issue?

The issue on my end turned out to be related to this section of the documentation (https://shopify.dev/docs/apps/launch/deployment/deploy-web-app)

If you’re deploying to Fly.io and are using the Remix template and didn’t change its default SQLite database, the session data will be cleared from the database after the Fly.io machine restarts, causing the issue.

A volume should be created for the app according to this guide: https://fly.io/docs/apps/volume-storage/#add-volumes-to-an-existing-app, and the datasource block in schema.prisma should be updated accordingly (https://www.prisma.io/docs/orm/overview/databases/sqlite).

For example:

fly.toml:

...
[mounts]
  source="data"
  destination="/data"
...

schema.prisma:

...
datasource db {
  provider = "sqlite"
  url      = "file://data/dev.sqlite"
}
...

Sorry, meant to respond to OP.