Hi everyone,
I’m trying to build an embedded public app for Shopify using NodeJS (Express) backend and Svelte SPA frontend but am struggling to understand the overall auth flow. I’m trying to avoid the shopify-cli tool as it’s forcing me to use NextJS and I prefer to use Svelte.
The current app structure is as follows:
server.ngrok.io is the NodeJS /Express app
client.ngrok.io is a separate client side only app using Svelte (no server side rendering)
My app currently implements the following flow:
-
User enters app at server.ngrok.io/api/shopify-auth/
-
server.ngrok.io/api/shopify-auth/ redirects user to client.ngrok.io/install which is essentially just a skeleton Svelte page with the iframe escaping script per Shopify’s App Bridge guide, which redirects the user to the Shopify permission page
-
Shopify redirects back to server.ngrok.io/api/shopify-auth/callback
-
server.ngrok.io/api/shopify-auth/callback exchanges temp token for a permanent one, stores perm in my db
However, I’m encountering the following problem:
- If I redirect the user to client.ngrok.io from step 4 above, the app will open in a new window, not in the iframe. I’ve tried going to my test store’s admin → apps’ page and I could render the app but the AppBridge isn’t working as the host parameter is never passed to the AppBridge instance. How do I go about passing this host parameter to the my frontend app given that it’s only provided once during the OAuth flow?
- After browsing around, I realised the host is just a Base-64 string of the .myshopify.com/admin. I’ve tried generating this manually in the frontend app but now I’m encountering a different issue. Shopify won’t instantiate the AppBridge as the starting point in my partner dashboard is the server.ngrok.io host whereas the AppBridge is instantiated in client.ngrok.io host. Am I missing something? How should this be handled in a dev environment? I know I could do npm run build and serve the client from the backend but I’d lose all the hot reloading feature in development.
Appreciate it if anyone can help me solve both of these issues!
Cheers