Periodic re-authentication breaks Admin Link
Issue summary
Using the guide from https://shopify.dev/tutorials/build-a-shopify-app-with-node-and-react , I setup a Custom app for my store. It works well in general, and was straightforward to get running. I have found an issue that I am hopeful someone can help me with.
I added an Admin Link to my app, which points to https://{my-app-uri}/doSomething . Most times, clicking the link works as expected and I am brought directly to the desired section of my app. However, periodically it seems, I have to 're-auth' the app (after quitting the browser, after a full relaunch of my server, sometimes after 24 hours). What happens then is that when I click the Admin Link, it starts to load https://{my-app-uri}/doSomething , but then the re-auth happens, and I am redirected to the index screen of my app instead of where I was hoping to go.
Unfortunately, I don't see any trace of what the original URI was when the re-auth occurs. I was hoping somewhere in the Koa context I could see a full 'referer' field or similar showing the original Admin Link so I could redirect there instead of to '/', but that does not seem to be sent through. The challenge is that the Admin Link includes some query parameters that are sent by Shopify, and since I am losing those on the re-auth I can't just redirect to where the Admin Link previously was loading.
Is there a way to save the original URI Admin Link with query params so I can redirect to it after re-auth?
Expected behavior
Clicking an Admin Link should load through to the desired section of my app, including the original query params.
Actual behavior
Clicking an Admin Link when a re-auth is required forwards to my app's home screen instead of the desired section with none of the original query params.
Steps to reproduce the problem
- Setup an Admin Link (from the Partners dashboard, open your app, then go to Extensions; mine are on the Draft Order Details and Order Details pages)
- Remove all cookies for your app's domain
- Use the Admin Link in your store
- You will be redirected to the index page of the app instead of the desired section
One thing I've been trying is to modify the redirectToAuth function in utilities to add a redirect querystring param with the ctx.originalUrl. I can get this to work with a single request workflow, but would need to make sure that the redirect key kept being passed around for production to properly handle multiple concurrent requests.
I've also noticed this behavior and looking for a fix.
I am using the Shopify APP CLI.
It can be a big issue as I am adding my app ScriptTag in the afterAuth and this is causing my script to be added multiple times on the client storefront.
Hi, do you have a tip, how to resolve this issue? Thanks 🙂
Note that this repo is no longer maintained and this issue will not be reviewed. Prefer the official JavaScript API library. If you still want to use Koa, see simple-koa-shopify-auth for a potential community solution.