Cannot complete OAuth process. No session found for the specified shop url

Currently I’m building out an express app using the Shopify tutorial for node.js and express.js, but I run into an error that states: Error: Cannot complete OAuth process. No session found for the specified shop url: store_url.com . The error occurs at: await Shopify.Auth.validateAuthCallback().

var router = require("express").Router();
module.exports = router;
var Shopify = require("@shopify/shopify-api").Shopify;
var ApiVersion = require("@shopify/shopify-api").ApiVersion;

Shopify.Context.initialize({
  API_KEY: process.env.SHOPIFY_API_KEY,
  API_SECRET_KEY: process.env.SHOPIFY_API_SECRET,
  SCOPES: process.env.SHOPIFY_API_SCOPES,
  HOST_NAME: global.env.ROOT_URL.replace(/https:\/\//, "") + "/api/shopify",
  API_VERSION: ApiVersion.Unstable,
  IS_EMBEDDED_APP: false,
});

var shops = [];
router.get("/", async function (req, res, next) {
  if(typeof shops[req.query.shop] !== 'undefined') {
    console.log("Already Logged Signed Up");
  }else{
    res.redirect("/api/shopify/auth?shop="+req.query.shop);
  }
});

router.get("/auth", async function (req, res, next) {
  const authRoute = await Shopify.Auth.beginAuth(req, res, req.query.shop, '/auth/callback', false);
  res.redirect(authRoute);
});

router.get("/auth/callback", async function (req, res, next) {
  const shopSession = await Shopify.Auth.validateAuthCallback(req, res, req.query);
  shops[req.query.shop] = shopSession;
  res.redirect("");
});

Can you share your session SESSION_STORAGE (especially the load and store functions)? It is most likely the source of error.

This error is raised because in the app is not able to load the session stored see this code where this error is raised here.

Some nit remarks about your code

  1. In your initialization it does not seem that you set SESSION_STORAGE explicitly, I would recommend setting that explicitly.
  2. Your host name has a suffix that you again call in the redirect here, not sure if this is causing any issue res.redirect("/api/shopify/auth?shop="+req.query.shop);
  3. What is the motivation of using unstable API?

I did find the solution. I changed versions of the API from unstable to most recent stable and updated my library. That seems to have fixed it.

Thank You

Hi Mikhail, what api did you change and to what version?

Could you show the code example please?

Thank you!