Shopify / shopify-app-template-node

MIT License
879 stars 398 forks source link

InternalServerError: Cannot complete OAuth process. Could not find an OAuth cookie for shop url ... #585

Closed valorloff closed 2 years ago

valorloff commented 3 years ago

Issue summary

Issues navigations after app been installed

Write a short description of the issue here ↓ Installation and billing app parts was successful, but attempt navigate to index route return POST https://ngrok.XXXX/graphql 401 (Unauthorized)

Expected behavior

Navigation worked fine in the old api without any problem

What do you think? My opinion: problem with session tokens, possible reason: SSR rendered page lost session token, but not regenerate new one

Actual behavior

What actually happens? Click nav link results browser error: 'bad request'. If reload page: server error:

 InternalServerError: Cannot complete OAuth process. Could not find an OAuth cookie for shop url: XXX.myshopify.com
      at Object.throw (/home/~/node_modules/koa/lib/context.js:97:11)
      at /home/~/node_modules/@shopify/koa-shopify-auth/dist/src/auth/index.js:100:42
      at step (/home/~/node_modules/tslib/tslib.js:141:27)
      at Object.throw (/home/~/node_modules/tslib/tslib.js:122:57)
      at rejected (/home/~/node_modules/tslib/tslib.js:113:69)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

If i delete app from devStore, then install it back on, installation process and initial page works nice.

In the docs, you mentioned that tokens need to be written to the database for later use. Could you show example of using saved Access and Session Token, please?

Crunchyman-ralph commented 3 years ago

Having the same issue, works on index, but as soon as I want to navigate anywhere else, I get the error:

InternalServerError: Cannot complete OAuth process. Could not find an OAuth cookie for shop url: XXX.myshopify.com
┃       at Object.throw (C:\xxx\xxx\Documents\GitHub\xxx\node_modules\koa\lib\context.js:97:11)
┃       at C:\xxx\xxx\Documents\GitHub\xxx\node_modules\@shopify\koa-shopify-auth\dist\src\auth\index.js:100:42
┃       at step (C:\xxx\xxx\Documents\GitHub\xxx\node_modules\tslib\tslib.js:141:27)
┃       at Object.throw (C:\xxx\xxx\Documents\GitHub\xxx\node_modules\tslib\tslib.js:122:57)
┃       at rejected (C:\xxx\xxx\Documents\GitHub\xxx\node_modules\tslib\tslib.js:113:69)
┃       at runMicrotasks (<anonymous>)
┃       at processTicksAndRejections (internal/process/task_queues.js:97:5)

Would love to get an insight as to what might be going on.

hbittelbrunn commented 3 years ago

I was having the same issue, in my case, it was related to Navigation config in the App Extention in the Partner Portal. I was pointing to the "/index" and the app was actually routing to "index/index.js", making the Nav get stuck. Refreshing the page was breaking the OAuth process returning the Internal Server Error (OAuth) described above. Removing the "/index" from the Nav config in the Partner portal fixed my issue. Not sure if your issue is the same, just sharing my case.

valorloff commented 3 years ago

Yes, this solved! I also leaning towards this conclusion before your post But that's only half of the problem. Remain problem of page reload (FastRefresh) during dev process, which throws out GET https://ngrokXXX/auth 400 (Bad Request) To return to workflow, need to reinstall the app

akhilmhdh commented 3 years ago

Hi @valorloff Did u fixed this issue.

Suddenly my app in development is also firing this error saying

  InternalServerError: Cannot complete OAuth process. Could not find an OAuth cookie for shop url: 

Can someone address why this error happens. I am following the latest node + react demo using memory session and online token.

Ok found out that the server keeps on redirecting me to this point https://127.0.0.1:3000/auth/inline?shop=<shop-name>. And this fails. Getting so confused. 😢

valorloff commented 3 years ago

Hi @akhilmhdh! the problem lies somewhere inside @shopify/koa-shopify-auth, as far as i understand, React Fast Refresh loses session token, and it takes a lot of time to resume work, you need full root page ('/') reload, over and over again And, what is "inline" section in url that you provided ?

akhilmhdh commented 3 years ago

I actually really dont know. Shopify just keeps on redirecting me to this section, and then fails as the domain is invalid.

akhilmhdh commented 3 years ago

Just an update here on the issue i was facing

The thing is my ngrok was getting timed out frequently. So development was really bad and I ended up connecting to an ec2 instance server using vscode ssh to develop shopify app. I was using Nginx as proxy and my bad there was an error in my reverse proxy. It fixed this issue.

I'll soon be writing a series of articles on developing shopify app which will address all the issues that I have faced. 😃

palashkulsh commented 3 years ago

for anyone facing the error that shopify is redirecting you to localhost:8081 even when HOST variable is set correctly in .env file and you are nginx to proxy requests then I solved the issue by passing host header from nginx proxypass

server {
        listen 443 ssl default;
        listen [::]:443 ssl;
        include snippets/self-signed.conf;
        include snippets/ssl-params.conf;
        server_name example.com www.example.com ;
        proxy_set_header Host "$http_host";
        location / {
                proxy_pass http://localhost:8081;
        }

This was happening because apparently shopify creates a html script tag response using location header.

nandumoura commented 3 years ago

I was having the same issue, in my case, it was related to Navigation config in the App Extention in the Partner Portal. I was pointing to the "/index" and the app was actually routing to "index/index.js", making the Nav get stuck. Refreshing the page was breaking the OAuth process returning the Internal Server Error (OAuth) described above. Removing the "/index" from the Nav config in the Partner portal fixed my issue. Not sure if your issue is the same, just sharing my case.

Thanks this solve for me

github-actions[bot] commented 2 years ago

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

github-actions[bot] commented 2 years ago

We are closing this issue because it has been inactive for a few months. This probably means that it is not reproducible or it has been fixed in a newer version. If it’s an enhancement and hasn’t been taken on since it was submitted, then it seems other issues have taken priority.

If you still encounter this issue with the latest stable version, please reopen using the issue template. You can also contribute directly by submitting a pull request– see the CONTRIBUTING.md file for guidelines

Thank you!