nestjs-shopify / example-nx-app

Example monorepo app with @nest-shopify/nest-shopify using NestJS backend and NextJS frontend
30 stars 9 forks source link

Cannot complete OAuth process. Could not find an OAuth cookie for shop url #85

Open lutitech opened 1 year ago

lutitech commented 1 year ago

After installation and get this error on my cli. Am only using the nest Api. `Nest] 1376 - 07/05/2023, 6:19:34 PM LOG [Shopify] [2023-07-05T17:19:34Z] [shopify-api/INFO] Beginning OAuth | {shop: movitt.myshopify.com, isOnline: true, callbackPath: /api/online/callback} [Nest] 1376 - 07/05/2023, 6:19:34 PM LOG [Shopify] [2023-07-05T17:19:34Z] [shopify-api/DEBUG] OAuth started, redirecting to https://movitt.myshopify.com/admin/oauth/authorize?client_id=9a9b833688216761f62b0b282b7959a3&scope=write_products%2Cwrite_orders&redirect_uri=https%3A%2F%2F3f5e-197-211-53-125.ngrok-free.app%2Fapi%2Fonline%2Fcallback&state=380819473534067&grant_options%5B%5D=per-user | {shop: movitt.myshopify.com, isOnline: true} [Nest] 1376 - 07/05/2023, 6:19:37 PM LOG [Shopify] [2023-07-05T17:19:37Z] [shopify-api/INFO] Completing OAuth | {shop: movitt.myshopify.com} [Nest] 1376 - 07/05/2023, 6:19:37 PM LOG [Shopify] [2023-07-05T17:19:37Z] [shopify-api/DEBUG] OAuth request is valid, requesting access token | {shop: movitt.myshopify.com} [Nest] 1376 - 07/05/2023, 6:19:37 PM LOG [Shopify] [2023-07-05T17:19:37Z] [shopify-api/DEBUG] Making HTTP request - POST https://movitt.myshopify.com/admin/oauth/access_token - Headers: {"User-Agent":["Shopify API Library v7.4.0 | Node v18.16.0"],"Content-Type":["application/json"],"Content-Length":["141"]} - Body: "{\"client_id\":\"9a9b833688216761f62b0b282b7959a3\",\"client_secret\":\"0ee97e276007eaae592d8cdbc239bdd2\",\"code\":\"838fcfe1c7c3b3c3abfaf35440d2f6cf\"}" [Nest] 1376 - 07/05/2023, 6:19:38 PM LOG [Shopify] [2023-07-05T17:19:38Z] [shopify-api/DEBUG] Completed HTTP request, received 200 OK [Nest] 1376 - 07/05/2023, 6:19:38 PM LOG [Shopify] [2023-07-05T17:19:38Z] [shopify-api/INFO] Creating new session | {shop: movitt.myshopify.com, isOnline: true} [Nest] 1376 - 07/05/2023, 6:27:58 PM LOG [Shopify] [2023-07-05T17:27:58Z] [shopify-api/INFO] Completing OAuth | {shop: movitt.myshopify.com} [Nest] 1376 - 07/05/2023, 6:27:58 PM LOG [Shopify] [2023-07-05T17:27:58Z] [shopify-api/ERROR] Could not find OAuth cookie | {shop: movitt.myshopify.com} [Nest] 1376 - 07/05/2023, 6:27:58 PM ERROR [ExceptionsHandler] Cannot complete OAuth process. Could not find an OAuth cookie for shop url: movitt.myshopify.com

Error: Cannot complete OAuth process. Could not find an OAuth cookie for shop url: movitt.myshopify.com at Object. (C:\Users\user\Desktop\movit\erp-plugin-shopify\node_modules\@shopify\shopify-api\lib\auth\oauth\oauth.ts:159:13) at Generator.next () at fulfilled (C:\Users\user\Desktop\movit\erp-plugin-shopify\node_modules\tslib\tslib.js:164:62) at processTicksAndRejections (node:internal/process/task_queues:95:5)`

bekkazy-k commented 1 year ago

I have the same problem, any updates?

lutitech commented 1 year ago

I could not solve it so I decide to use axios instead of this library

tolgap commented 1 year ago

@bekkazy-k @lutitech Can you show me your ShopifyCoreModule.forRoot and ShopifyAuthModule.forRootOnline call. It's impossible to know whats going wrong when there's no code shown.

Please show the actual values being used to these two modules. But don't expose your clientSecret here.

bekkazy-k commented 1 year ago

@tolgap

    ShopifyCoreModule.forRootAsync({
      imports: [SessionStorageModule],
      inject: [EnvConfigService, SessionRepository],
      useFactory: async (
        config: EnvConfigService,
        sessionStorage: SessionRepository,
      ): Promise<ShopifyCoreOptions> => ({
        sessionStorage,
        apiKey: config.getShopifyApiKey,
        apiSecretKey: config.getShopifyApiSecret,
        apiVersion: ApiVersion.July23,
        isEmbeddedApp: true,
        hostName: config.getHostName
        scopes: ['read_products'],
      }),
    }),
    ShopifyAuthModule.forRootAsyncOffline({
      imports: [EnvConfigModule, AfterAuthModule],
      inject: [AfterAuthHandlerService],
      useFactory: (config: EnvConfigService, afterAuthHandler: AfterAuthHandlerService) => ({
        basePath: '/offline',
        useGlobalPrefix: true,
        returnHeaders: true,
        afterAuthHandler,
      }),
    }),
    ShopifyAuthModule.forRootAsyncOnline({
      imports: [EnvConfigModule, AfterAuthModule],
      inject: [AfterAuthHandlerService],
      useFactory: (config: EnvConfigService, afterAuthHandler: AfterAuthHandlerService) => ({
        basePath: '/online',
        useGlobalPrefix: true,
        afterAuthHandler,
      }),
    }),
bekkazy-k commented 1 year ago

@tolgap I tried to run this example without any code changes (only api key and api secret key) and I get the same response. The installation goes fine and only when you open the application an error appears

tolgap commented 1 year ago

@bekkazy-k @lutitech I will soon try installing this demo app on a fresh store and a fresh app. I cannot seem to replicate it.

Ivanshamir commented 1 year ago

@tolgap Is there any update about this? I have similar problem. The installation is okay but when I try to open application the error appears. Thank you.

tolgap commented 1 year ago

@Ivanshamir I actually haven't been able to replicate this issue on my stores.

It might be worth clearing the cookies that @shopify/shopify-api places on your applications HOST url. Can you try that and then revisiting the installation URL for the offline auth?

Ivanshamir commented 1 year ago

Hello @tolgap thank you for your response. The issue is however comes from web. Strangely AlphaStack from '@shopify/polaris' doesn't work as expected, so I remove those from index.tsx and ProductsCard.tsx. I don't know why this isn't working. I will try to find out this later. And thank you so much for this great repo. Cheers!

tolgap commented 12 months ago

@Ivanshamir I fixed the AlphaStack references in the example app! Apparently an autoupdate PR got merged for Polaris that introduced breaking changes on that Polaris component.