Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

afterAuth not run when installing in Remix App #674

Open
NguyenQuangHuy282002 opened this issue Feb 28, 2024 · 4 comments
Open

afterAuth not run when installing in Remix App #674

NguyenQuangHuy282002 opened this issue Feb 28, 2024 · 4 comments

Comments

@NguyenQuangHuy282002
Copy link

NguyenQuangHuy282002 commented Feb 28, 2024

Issue summary

  • "@shopify/shopify-api": "^9.0.1",
    "@shopify/shopify-app-remix": "^2.3.0",
  • Node version: 20
  • Operating system: MACOS
const shopify = shopifyApp({
  apiKey: process.env.SHOPIFY_API_KEY,
  apiSecretKey: process.env.SHOPIFY_API_SECRET || '',
  apiVersion: LATEST_API_VERSION,
  scopes: process.env.SCOPES?.split(','),
  appUrl: process.env.SHOPIFY_APP_URL || '',
  authPathPrefix: '/auth',
  sessionStorage: new MongoDBSessionStorage(new URL(process.env.DATABASE_URL || ''), ''),
  // sessionStorage: new PrismaSessionStorage(prisma),
  distribution: AppDistribution.AppStore,
  restResources,
  webhooks: {
    [APP_UNINSTALLED]: {
      ...DEFAULT_WEBHOOK_METHOD,
    },
    [CUSTOMERS_DATA_REQUEST]: {
      ...DEFAULT_WEBHOOK_METHOD,
    },
    [CUSTOMERS_REDACT]: {
      ...DEFAULT_WEBHOOK_METHOD,
    },
    [SHOP_REDACT]: {
      ...DEFAULT_WEBHOOK_METHOD,
    },
    [SHOP_UPDATE]: {
      ...DEFAULT_WEBHOOK_METHOD,
    },
  },
  hooks: {
    afterAuth: async ({ session, admin }) => {
console.log('Run after auth hook')
      shopify.registerWebhooks({ session })

      await Promise.all([initShopData(admin, session), installApp(prisma, admin.graphql, session)])
    },
  },
  future: {
    v3_webhookAdminContext: true,
    v3_authenticatePublic: true,
  },
  ...(process.env.SHOP_CUSTOM_DOMAIN ? { customShopDomains: [process.env.SHOP_CUSTOM_DOMAIN] } : {}),
})

Expected behavior

Run afterAuth callback after installed

Actual behavior

Not run afterAuth callback after installed, however, run it when navigating to other routes in app

Steps to reproduce the problem

  1. Install app
  2. Check the afterAuth callback is run by logging in terminal
@thorupio
Copy link

thorupio commented Mar 6, 2024

Also experiencing this

@thorupio
Copy link

thorupio commented Mar 6, 2024

fwiw, I'm seeing this being logged if I set logger: { level: LogSeverity.Debug }

[shopify-app/DEBUG] App is not embedded, redirecting to Shopify | {shop:{redacted}.myshopify.com}

But the app IS embedded

@gnikyt
Copy link

gnikyt commented Apr 3, 2024

I ran across this issue, this whole product is just unfinished and buggy unfortunately. Every app we develop, we run into issues directly related to the framework Shopify is suggesting to use... super frustrating.

In this case, I decided to spin up a new app just to see if that would resolve the issue, via npm run dev -- --reset and going through the steps to setup a new app.

I then went onto the existing app's configuration page in the Partners portal, and compared it to the new app that was just setup. I noticed the old app had no scopes section in the partners page, the new app did. So something has been changed along the way, unsure what.

However, creating a new app did resolve the issue.

Additionally, the root issue appears to be the installation URL provided under Distribution, did not end up containing a ?embedded=1 URL param as part of the install/redirects, which caused it to think it was not embedded (node_modules/@shopify/shopify-app-remix/build/cjs/server/authenticate/admin/helpers/ensure-app-is-embedded-if-required.js -- line 15).

So, try creating a new app.

@david1542
Copy link

david1542 commented May 5, 2024

I'm also experiencing this issue :(
I've just created a new application and the afterAuth is not fired. I'm not sure why.

EDIT: ok turns out I had to delete my local sqlite db and delete the session. Afterwards, the afterAuth was run correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants