Search code examples
shopifyshopify-app

Where to add custom code that will execute after the user installs the shopify app?


I'm attempting to generate new metafield definitions after the user accepts the app installation. However, I'm having a hard time determining where to place my code for generating the definitions. Currently I'm using Remix Template using nodejs in my APP.

Upon my investigation, the following are called during the app installation process:

  1. The afterAuth hook, which can be found in the app/shopify.server.ts file.
  2. Creating a route for auth/callback (I created this file: app/routes/auth.callback/route.tsx).
  3. On the app/routes/auth.$.tsx route.

I'm unsure which of the above options is best to use for (3) or if it's recommended to use any of the options mentioned. Could someone guide me in the right direction?


Solution

  • AfterAuth is the right place. Usually your framework will call that job for you, meaning you just have to write the code to get the auth token, and then make your API call.

    note that this pattern is a PITA though, because reliance on it means you can't fiddle so easily with it after the fact and have all stores run your new code. It is only on after auth, which in many cases is never called after install.

    My silly workaround that was always to force an auth with the /login route but that is bush league IMO for lack of a better way.