Closed kylebuildsstuff closed 3 years ago
Sorry for the slow reply on this! We dug into the issue and it looks like the host
encoding could be causing the problem here. Your approach of getting the host value from the query is preferred but if it doesn't find that (eg. in the initial installation) it's going to fall back to window.btoa?.(shopOrigin)
. Instead of btoa
, we recommend using base64url
as it is url safe. You're also going to be missing /admin
from that shopOrigin
value, so you can append it manually.
Also note that you shouldn't include the shopOrigin
option in your config as of v2.
Could you try something like this?
import base64url from 'base64url';
let shopOrigin = action?.query?.shop;
let host = action?.query?.host || base64url(shopOrigin + '/admin');
const appBridgeConfig = {
apiKey: process.env.REACT_APP_SHOPIFY_API_KEY as string,
host,
forceRedirect: true,
};
Adding the + '/admin' fixed everything!
Thank you for looking into this issue, it took me days before I settled on patching the node_modules directly but your solution is perfect.
Describe the bug
When the
forceRedirect
option is declared on AppBridge, accessing the app through the app domain specified in the partner dashboard redirects the user to a 404 page. AppBridge forces the redirect as expected but it redirects to a broken page.This breaks flow for app subscriptions when using the returnUrl and it prevents apps from passing the review stage if the reviewer accesses the app from the app domain, which my last reviewer did.
To Reproduce
My config looks like this:
My return url for the app subscription:
https://${process.env.APP_DOMAIN}/admin${ shopOrigin ?`?shop=${shopOrigin}&host=${host}`: '' }
,Though the bug can be reproduced without going through the process of setting up an appSubscription, but just accessing the app at the app domain specified in the partner dashboard with the shop attached:
https://<appDomainUrl>/admin?shopOrigin=<shopOrigin>
Expected behaviour
When accessing the app through the app domain, app bridge should redirect to the admin as it did in version 1.30.0.
Actual behaviour
When accessing the app through the app domain, the app redirects to
https://<shopDomain>/apps/<publicKey>/admin?shop...
, which does not exist and presents a 404:Contextual information
Packages and versions
List the relevant packages you’re using, and their versions. For example:
Platform
Additional context
Using node/koa on backend and react/redux on frontend.
I traced the code back into node_modules and found @shopify/app-bridge/client/Client.js the redirect code:
v.2.0.3
If I add "admin" after "host" and before "/apps/" then the redirect works properly. I also found the same code in version 1.30.0 and it seems to have a different redirect url that still works for me:
v.1.30.0: