Oauth error invalid_request: Could not find Shopify API application with api_key [React, Node]

cleverlydone
New Member
1 0 0

I'm having a issue getting my store to install a app I made. Fairly new to the shopify developer but I followed the tutorial to the tee. Maybe I'm missing something here? I am following this tutorial https://shopify.dev/tutorials/build-a-shopify-app-with-node-and-react 

server.js

 

require("isomorphic-fetch");
const dotenv = require("dotenv");
const Koa = require("koa");
const next = require("next");
const { default: createShopifyAuth } = require("@shopify/koa-shopify-auth");
const { verifyRequest } = require("@shopify/koa-shopify-auth");
const { default: Shopify, ApiVersion } = require("@shopify/shopify-api");
const Router = require("koa-router");

dotenv.config();

Shopify.Context.initialize({
  API_KEY: process.env.SHOPIFY_API_KEY,
  API_SECRET_KEY: process.env.SHOPIFY_API_SECRET,
  SCOPES: process.env.SHOPIFY_API_SCOPES.split(","),
  HOST_NAME: process.env.SHOPIFY_APP_URL.replace(/https:\/\//, ""),
  API_VERSION: ApiVersion.October20,
  IS_EMBEDDED_APP: true,
  SESSION_STORAGE: new Shopify.Session.MemorySessionStorage(),
});

const port = parseInt(process.env.PORT, 10) || 3000;
const dev = process.env.NODE_ENV !== "production";
const app = next({ dev: dev });
const handle = app.getRequestHandler();

const ACTIVE_SHOPIFY_SHOPS = {};

app.prepare().then(() => {
  const server = new Koa();
  const router = new Router();
  server.keys = [Shopify.Context.API_SECRET_KEY];

  server.use(
    createShopifyAuth({
      afterAuth(ctx) {
        const { shop, scope } = ctx.state.shopify;
        ACTIVE_SHOPIFY_SHOPS[shop] = scope;
        ctx.redirect(`/?shop=${shop}`);
      },
    })
  );

  const handleRequest = async (ctx) => {
    await handle(ctx.req, ctx.res);
    ctx.respond = false;
    ctx.res.statusCode = 200;
  };

  router.get("/", async (ctx) => {
    const shop = ctx.query.shop;

    if (ACTIVE_SHOPIFY_SHOPS[shop] === undefined) {
      console.log("hit", shop); //shop comes up as undefined
      ctx.redirect(`/auth?shop=${shop}`);
    } else {
      await handleRequest(ctx);
    }
  });

  router.get("(/_next/static/.*)", handleRequest);
  router.get("/_next/webpack-hmr", handleRequest);
  router.get("(.*)", verifyRequest(), handleRequest);

  server.use(router.allowedMethods());
  server.use(router.routes());

  server.listen(port, () => {
    console.log(`> Ready on http://localhost:${port}`);
  });
});

 

 

.env

 

SHOPIFY_API_KEY=mykey
SHOPIFY_API_SECRET=mysecret
SHOPIFY_API_SCOPES=read_products
SHOPIFY_APP_URL=https://9d36759f4f0e.ngrok.io

 

 

Screenshot of the error:

shopify.PNG

 

package.json

 

{
  "name": "shopify-donation-widget",
  "version": "1.0.0",
  "description": "donation widget",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "node server.js",
    "build": "next build",
    "start": "NODE_ENV=production node server.js"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/pierregober/shopify-donation-widget.git"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/pierregober/shopify-donation-widget/issues"
  },
  "homepage": "https://github.com/pierregober/shopify-donation-widget#readme",
  "dependencies": {
    "@shopify/koa-shopify-auth": "^3.2.0",
    "@shopify/polaris": "^6.0.1",
    "@shopify/shopify-api": "^1.3.0",
    "@zeit/next-css": "^1.0.1",
    "dotenv": "^8.6.0",
    "isomorphic-fetch": "^3.0.0",
    "koa": "^2.13.1",
    "koa-router": "^8.0.8",
    "koa-session": "^6.1.0",
    "next": "^10.2.0",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "shopify-api-node": "^3.6.12",
    "webpack": "^5.21.1"
  }
}

 

0 Likes