Shopify / shopify-app-js

MIT License
290 stars 116 forks source link

Validating installation request process with "statusCode" undefined error #767

Open MyBaymax opened 11 months ago

MyBaymax commented 11 months ago

Descriptions

Validating installation request process with "statusCode" undefined error Requesting help. Thanks!🙏

Console Error Info

[shopify-api/INFO] Beginning OAuth | {shop: zhenggong.myshopify.com, isOnline: false, callbackPath: /auth/callback}
config.ts:117
TypeError: Cannot read properties of undefined (reading 'statusCode')
    at /Users/baymax/Desktop/onezerocom/shopify-apps/app-01-remix-vite-express/node_modules/@shopify/shopify-api/adapters/node/adapter.js:23:49
    at Generator.next (<anonymous>)
    at /Users/baymax/Desktop/onezerocom/shopify-apps/app-01-remix-vite-express/node_modules/tslib/tslib.js:169:75
    at new Promise (<anonymous>)
    at Object.__awaiter (/Users/baymax/Desktop/onezerocom/shopify-apps/app-01-remix-vite-express/node_modules/tslib/tslib.js:165:16)
    at nodeConvertIncomingResponse (/Users/baymax/Desktop/onezerocom/shopify-apps/app-01-remix-vite-express/node_modules/@shopify/shopify-api/adapters/node/adapter.js:21:20)
    at /Users/baymax/Desktop/onezerocom/shopify-apps/app-01-remix-vite-express/node_modules/@shopify/shopify-api/lib/auth/oauth/oauth.js:30:75
    at Generator.next (<anonymous>)
    at fulfilled (/Users/baymax/Desktop/onezerocom/shopify-apps/app-01-remix-vite-express/node_modules/tslib/tslib.js:166:62) {stack: 'TypeError: Cannot read properties of undefine…e-express/node_modules/tslib/tslib.js:166:62)', message: 'Cannot read properties of undefined (reading 'statusCode')'}

installation request

http://127.0.0.1:9696/auth/login?hmac=7571c799cda164add5c0f8fc24e26e4b386d771b00a69e29429540fdfcb09c0c&host=YWRtaW4uc2hvcGlmeS5jb20vc3RvcmUvemhlbmdnb25n&session=733696841bc1e8ad14b7933c953e1cfa8ffa91b7f05d1250ef96666cdfb28f6f&shop=zhenggong.myshopify.com&timestamp=1702215512

shopify.server.ts

import "@shopify/shopify-api/adapters/node";
import { shopifyApi, LATEST_API_VERSION } from "@shopify/shopify-api";
import { AppConfig } from "./config";

const shopify = shopifyApi({
  apiKey: AppConfig.SHOPIFY_API_KEY,
  apiSecretKey: AppConfig.SHOPIFY_API_SECRET,
  scopes: AppConfig.SCOPES.split(","),
  apiVersion: LATEST_API_VERSION,
  hostScheme: AppConfig.HOST_SCHEME,
  hostName: AppConfig.SHOPIFY_APP_URL,
  isEmbeddedApp: false,
  level: "debug",
});

export default shopify;

auth.login.ts

import type { LoaderFunctionArgs } from "@remix-run/node";
import shopify from "../shopify.server";
import { AppConfig } from "../config";

export const loader = async ({ request }: LoaderFunctionArgs) => {
  const { searchParams } = new URL(request.url);
  let shop = searchParams.get("shop");
  shop = shop && shopify.utils.sanitizeShop(shop, true);
  if (!shop) return "shop is null";
  return await shopify.auth.begin({
    shop,
    callbackPath: AppConfig.CALLBACK_PATH,
    isOnline: AppConfig.IS_ONLINE,
    rawRequest: request,
  });
  return null;
};
MyBaymax commented 11 months ago

additional

versions

@shopify/shopify-api => v8.1.1 node => v18.18.2

lizkenyon commented 11 months ago

Hi there 👋

We have had a few reports of this, but we have been unable to reproduce it on our side.

Would you have any more details around the actions you took before this started happening?

Was this on a fresh install? Did you uninstall and reinstall? Did you stop the server and uninstall?

If you have any more details or could provide us with code that can consistently reproduce that issue that would be very helpful for debugging.

MyBaymax commented 10 months ago

@lizkenyon

非常感谢您的关注。 对于该问题我使用 shopify-app-remix 替代 shopify-api-js。 在shopify-app-remix不会出现该问题。 import "@shopify/shopify-app-remix/server/adapters/node";

Thank you very much for your attention. For this issue, I will use shopify-app-remix instead of shopify-api-js. This issue will not occur in shopify-app-remix. Import "@ shopify/shopify-app-remix/server/adapters/node";

MyBaymax commented 10 months ago

Hi there 👋

We have had a few reports of this, but we have been unable to reproduce it on our side.

Would you have any more details around the actions you took before this started happening?

Was this on a fresh install? Did you uninstall and reinstall? Did you stop the server and uninstall?

If you have any more details or could provide us with code that can consistently reproduce that issue that would be very helpful for debugging.

@lizkenyon I have rebuilt the project and this is the project repository connection https://github.com/MyBaymax/remix-shopify Looking forward to your reply 🙏

github-actions[bot] commented 8 months ago

We're labeling this issue as stale because there hasn't been any activity on it for 60 days. While the issue will stay open and we hope to resolve it, this helps us prioritize community requests.

You can add a comment to remove the label if it's still relevant, and we can re-evaluate it.

jjrise commented 7 months ago

@MyBaymax did you ever figure this out? This is still happening to me...

jjrise commented 6 months ago

There seems to be a trend of this happening if I tried app installations in quick succession.

MyBaymax commented 6 months ago

There seems to be a trend of this happening if I tried app installations in quick succession.

@jjrise

I found that the problem was request. So I use express to handle authentication requests, and this is my solution.

router.use("/login", async (req: Request, res: Response) => {
  const shop = shopify.utils.sanitizeShop(req.query.shop as string);
  try {
    if (!shop) throw new Error("缺少 Shop");
    return await shopify.auth.begin({
      shop,
      callbackPath: process.env.SHOPIFY_APP_CALLBACK_PATH,
      isOnline: process.env.SHOPIFY_APP_IS_EMBEDDED,
      rawRequest: req,
      rawResponse: res,
    });
  } catch (error) {
    res.status(400).json(error);
  }
});
github-actions[bot] commented 4 months ago

We're labeling this issue as stale because there hasn't been any activity on it for 60 days. While the issue will stay open and we hope to resolve it, this helps us prioritize community requests.

You can add a comment to remove the label if it's still relevant, and we can re-evaluate it.