Code Monkey home page Code Monkey logo

Comments (4)

TheSecurityDev avatar TheSecurityDev commented on July 29, 2024 2

Most likely it's in your load session function which gets called by the Shopify library when this library does the authentication, which causes the error to appear like it's coming from this package. I would add a try-catch block around your load session function to see if you can track down the error. Feel free to reopen this issue if you think it is an issue after all.

from simple-koa-shopify-auth.

TheSecurityDev avatar TheSecurityDev commented on July 29, 2024

Can this be reproduced in a development environment? I don't see anywhere where an id is being accessed in that part of the code, so it's either in the Shopify API library or in your code. Could you share the entire code you're using for the afterAuth function? Unfortunately the error message isn't very helpful because it doesn't show where the id failed to be read.

The second error message is a Shopify server error, so I would assume it's because the session wasn't created properly or something.

from simple-koa-shopify-auth.

TheSecurityDev avatar TheSecurityDev commented on July 29, 2024

Just to confirm is this happening in development or production?

from simple-koa-shopify-auth.

FourLineCode avatar FourLineCode commented on July 29, 2024

This is happening in production, on a heroku deployment. And it might not be related to this library. I have done some digging, and it might be something to do with Shopify.Utils.loadCurrentSession. So, probably can close the issue for now.

Also heres the full code for afterAuth -

server.use(
    createShopifyAuth({
      accessMode: "offline",
      afterAuth: async (ctx) => {
        const { shop, accessToken, scope } = ctx.state.shopify;
        ACTIVE_SHOPIFY_SHOPS[shop] = scope;
        ctx.query.token = accessToken;

        // Store shop scopes and access token in firestore
        await setDoc(doc(db, "tokens", shop), {
          shop,
          scope,
          accessToken,
        });

        // Register all webhooks
        const responses = await Promise.all(
          webhooks.map(({ topic }) =>
            Shopify.Webhooks.Registry.register({
              topic,
              shop,
              accessToken,
              path: "/webhooks",
            })
          )
        );

        responses.forEach((response, index) => {
          const topic = webhooks[index].topic;
          if (!response[topic].success) {
            console.log(`Failed to register ${topic} webhook: ${response.result}`);
          }
        });

        // NOTE: This currently doesnt work as heroku deployment restarts after 30 mins of inactivity and removes all existing data
        // Deleting metafield on app reinstall if in production only
        // if (!DEV && responses[0].APP_UNINSTALLED.success) {
        //   await deleteAllMetafield({ shop, accessToken });
        // }

        await Promise.all([
          // Save the default settings object
          saveDefaultSettings(shop, accessToken),
          // Update the default store theme
          updateTheme(shop, accessToken),
          // Create a default collection
          createCollection(shop, accessToken),
        ]);

        ctx.redirect(`https://${shop}/admin/apps/${process.env.SHOPIFY_API_KEY}`);
      },
    })
  );

from simple-koa-shopify-auth.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.