Shopify / shopify-app-template-remix

332 stars 140 forks source link

"No valid session found and Requesting offline access token" info occurs when opening the app. #561

Closed chenluhe closed 5 months ago

chenluhe commented 7 months ago

Steps:

  1. Clone the "shopify-app-template-remix" project locally, enter the project directory, and execute the npm install and npm run dev commands respectively.
  2. Then press the "P" key to install the app. After the installation is completed, the page will be blank.

The error log is as follows:

chenluhedeMacBook-Pro:shopify-app-template-remix chenluhe$ npm run dev

dev shopify app dev ...... ...... ...... 20:47:02 │ remix │ [shopify-app/INFO] No valid session found 20:47:02 │ remix │ [shopify-app/INFO] Requesting offline access token 20:47:02 │ remix │ [shopify-app/INFO] No valid session found 20:47:02 │ remix │ [shopify-app/INFO] Requesting offline access token 20:47:18 │ remix │ GET /app?embedded=1&hmac=2deefb8f94b3b37ad4e8484a29481cb9fb979bd32b3fb4dfac7c6d5b8acf88e6&host=YWRtaW4uc2hvcGlmeS5jb20vc3Rvcm UvbHVoZWRldg&id_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwczpcL1wvbHVoZWRldi5teXNob3BpZnkuY29tXC9hZG1pbiIsImRlc3QiOiJodHRwczpcL1wvbH VoZWRldi5teXNob3BpZnkuY29tIiwiYXVkIjoiZDg4YmYwMzU5YzE0M2JlNzAxOTBiN2ZhZTJjMTU1ZGQiLCJzdWIiOiIxMDYzNDIzNTExNTgiLCJleHAiOjE3MDg0MzMyNzcsIm5iZiI6MTcwODQ zMzIxNywiaWF0IjoxNzA4NDMzMjE3LCJqdGkiOiI0YjU2YTUxZi0wYzIwLTRjZmUtODRjOS00MmI5MmY1OWJkZDAiLCJzaWQiOiIzZjlkOTM4NC0wMmI2LTQxOWItYTU2Zi0yZWExMjA2OTNkMDMi LCJzaWciOiIxYTZlMmRmN2ZhNWRhZmQ5YTg5YTY3MzQ3N2YyNWE1NDMzYjc4MzUwYTAzYmNkNTRiZGUwNGYyZmYxODlmY2I3In0.qJmEvJmrejppSAQgAOdOU0ADsq_9T_nJW1Mf1T2S8pg&local e=zh-CN&session=5184ec4af111d6e037471b9578c1ada1b1ea52ba76b90f69af906cecfb622501&shop=luhedev.myshopify.com&timestamp=1708433217 500 - - 15474.066 ms ....... ...... ......

Zardw commented 7 months ago

I also met a similar error. I just created the app, but when I ran it, a Handling response error occurred.

image

chenluhe commented 7 months ago

I also met a similar error. I just created the app, but when I ran it, a Handling response error occurred.

image

Latest progress: I found that the reason is that there is no data in the Session table. Why is there no data? Ignore this reason for now. I manually added a record to the Session table, similar to this:

image

Then after reopening the app, this error no longer occurred, and the app page could be displayed normally.

rachel-carvalho commented 7 months ago

Hi there, I'd like to clarify that the log messages No valid session found and Requesting offline access token are not errors. They're just INFO messages to let you know that the app doesn't have an access token for the store that's accessing the app and that it will fetch one. We do expect the Session table to be empty the first time you run an app, since it hasn't been installed yet.

I do see in your logs this line 20:47:18 │ remix │ GET /app?embedded=1&hmac=[...] 500 - - 15474.066 ms indicating the request resulted in an unhandled error with HTTP status 500. But I wasn't able to reproduce this issue following your steps.

If you're able to add a try/catch to share the details of that error we might be able to reproduce it.

Zardw commented 7 months ago

@rachel-carvalho this project is created by Shopify Cli, I haven't done any changes, run it directly, but it gets 500 error, cannot save the Session data into database. I created a project before, it could run normally, after some updates by them, newly created projects are not running properly.

chenluhe commented 7 months ago

Hi there, I'd like to clarify that the log messages No valid session found and Requesting offline access token are not errors. They're just INFO messages to let you know that the app doesn't have an access token for the store that's accessing the app and that it will fetch one. We do expect the Session table to be empty the first time you run an app, since it hasn't been installed yet.

I do see in your logs this line 20:47:18 │ remix │ GET /app?embedded=1&hmac=[...] 500 - - 15474.066 ms indicating the request resulted in an unhandled error with HTTP status 500. But I wasn't able to reproduce this issue following your steps.

If you're able to add a try/catch to share the details of that error we might be able to reproduce it.

This is an exception message: ...... ...... ...... 00:27:07 │ remix │ [shopify-app/INFO] No valid session found 00:27:07 │ remix │ [shopify-app/INFO] Requesting offline access token 00:27:07 │ remix │ [shopify-app/INFO] No valid session found 00:27:07 │ remix │ [shopify-app/INFO] Requesting offline access token 00:27:23 │ remix │ request error 00:27:23 │ remix │ Response { 00:27:23 │ remix │ size: 0, 00:27:23 │ remix │ [Symbol(Body internals)]: { 00:27:23 │ remix │ body: null, 00:27:23 │ remix │ type: null, 00:27:23 │ remix │ size: 0, 00:27:23 │ remix │ boundary: null, 00:27:23 │ remix │ disturbed: false, 00:27:23 │ remix │ error: null 00:27:23 │ remix │ }, 00:27:23 │ remix │ [Symbol(Response internals)]: { 00:27:23 │ remix │ url: undefined, 00:27:23 │ remix │ status: 500, 00:27:23 │ remix │ statusText: 'Internal Server Error', 00:27:23 │ remix │ headers: {}, 00:27:23 │ remix │ counter: 0, 00:27:23 │ remix │ highWaterMark: undefined 00:27:23 │ remix │ } 00:27:23 │ remix │ } 00:27:23 │ remix │ end request ...... ...... ......

koaqiu commented 6 months ago

I also met a similar error. I just created the app, but when I ran it, a Handling response error occurred. image

Latest progress: I found that the reason is that there is no data in the Session table. Why is there no data? Ignore this reason for now. I manually added a record to the Session table, similar to this: image

Then after reopening the app, this error no longer occurred, and the app page could be displayed normally.

你好,我有类似问题,你这手动添加的数据 是如何得到的?

我是用“ pnpm create @shopify/app”直接创建了一个 项目 运行然后 出现这问题 我什么都还没做,,,,,

Zardw commented 6 months ago

@koaqiu 我也是这样, 好像都是国内的, 可能触发的webhook事件没有添加店铺的session数据. 添加数据去数据库手动加, 运行app的payload里面有session数据

faner11 commented 6 months ago

I am also getting this error, my http://localhost:3457/graphiql is not responding. But when accessing other paths, I can get 404

image
faner11 commented 6 months ago
image

Here's my error,At first it is http 500, when I modify the file to trigger the HMR, then it will pop up http 401. hope you can make a comeback. @rachel-carvalho

16:38:57 │ remix    │ ---ERROR--- _Response [Response] {
16:38:57 │ remix    │   [Symbol(realm)]: { settingsObject: {} },
16:38:57 │ remix    │   [Symbol(state)]: {
16:38:57 │ remix    │     aborted: false,
16:38:57 │ remix    │     rangeRequested: false,
16:38:57 │ remix    │     timingAllowPassed: false,
16:38:57 │ remix    │     requestIncludesCredentials: false,
16:38:57 │ remix    │     type: 'default',
16:38:57 │ remix    │     status: 500,
16:38:57 │ remix    │     timingInfo: null,
16:38:57 │ remix    │     cacheState: '',
16:38:57 │ remix    │     statusText: 'Internal Server Error',
16:38:57 │ remix    │     headersList: _HeadersList {
16:38:57 │ remix    │       cookies: null,
16:38:57 │ remix    │       [Symbol(headers map)]: Map(0) {},
16:38:57 │ remix    │       [Symbol(headers map sorted)]: null
16:38:57 │ remix    │     },
16:38:57 │ remix    │     urlList: []
16:38:57 │ remix    │   },
16:38:57 │ remix    │   [Symbol(headers)]: _HeadersList {
16:38:57 │ remix    │     cookies: null,
16:38:57 │ remix    │     [Symbol(headers map)]: Map(0) {},
16:38:57 │ remix    │     [Symbol(headers map sorted)]: null
16:38:57 │ remix    │   }
16:38:57 │ remix    │ }
16:40:13 │ remix    │ ---ERROR--- _Response [Response] {
16:40:13 │ remix    │   [Symbol(realm)]: { settingsObject: {} },
16:40:13 │ remix    │   [Symbol(state)]: {
16:40:13 │ remix    │     aborted: false,
16:40:13 │ remix    │     rangeRequested: false,
16:40:13 │ remix    │     timingAllowPassed: false,
16:40:13 │ remix    │     requestIncludesCredentials: false,
16:40:13 │ remix    │     type: 'default',
16:40:13 │ remix    │     status: 401,
16:40:13 │ remix    │     timingInfo: null,
16:40:13 │ remix    │     cacheState: '',
16:40:13 │ remix    │     statusText: 'Unauthorized',
16:40:13 │ remix    │     headersList: _HeadersList {
16:40:13 │ remix    │       cookies: null,
16:40:13 │ remix    │       [Symbol(headers map)]: Map(0) {},
16:40:13 │ remix    │       [Symbol(headers map sorted)]: null
16:40:13 │ remix    │     },
16:40:13 │ remix    │     urlList: []
16:40:13 │ remix    │   },
16:40:13 │ remix    │   [Symbol(headers)]: _HeadersList {
16:40:13 │ remix    │     cookies: null,
16:40:13 │ remix    │     [Symbol(headers map)]: Map(0) {},
16:40:13 │ remix    │     [Symbol(headers map sorted)]: null
16:40:13 │ remix    │   }
16:40:13 │ remix    │ }
koaqiu commented 6 months ago

@koaqiu 我也是这样, 好像都是国内的, 可能触发的webhook事件没有添加店铺的session数据. 添加数据去数据库手动加, 运行app的payload里面有session数据

我试了一下,是有用。不过有没有最终解决方案啊

koaqiu commented 6 months ago

@koaqiu 我也是这样, 好像都是国内的, 可能触发的webhook事件没有添加店铺的session数据. 添加数据去数据库手动加, 运行app的payload里面有session数据

我发现 手动添加进去以后,还会有后续问题,能不能加个wx请教一下

Zardw commented 6 months ago

哈哈, 我也是刚开始学习这个, 之前的版本都是正常的, 新版本遇到了问题, 来这找答案, 但是他们一直没解决

chenluhe commented 6 months ago

应该就是国内网络问题,我这边时好时坏。。。

shaimeizi commented 6 months ago

@koaqiu 我也是这样, 好像都是国内的, 可能触发的webhook事件没有添加店铺的session数据. 添加数据去数据库手动加, 运行app的payload里面有session数据

@Zardw 我没找到session数据? 如何执行? 谢谢!

Zardw commented 6 months ago

随便填吧, 也没啥数据, state和token乱写的, 不知道对后续有什么影响.

image

shaimeizi commented 6 months ago

@Zardw 可以了,感谢!

damonchen commented 6 months ago

When no valid session found happened, the system will call token exchange url to get the token. Due to the gfw, the node fetch function could not connect the https://xxxx.myshopify.com/admin/oauth/access_token, and will be got the Timeout error.

coderlinbb commented 6 months ago

me too.

peihuanhuan commented 6 months ago

same to me

Zardw commented 6 months ago

@paulomarg @lizkenyon It's been a long time already. So many devs met this problem, why not nobody solve it?

pobed2 commented 6 months ago

When no valid session found happened, the system will call token exchange url to get the token. Due to the gfw, the node fetch function could not connect the https://xxxx.myshopify.com/admin/oauth/access_token, and will be got the Timeout error.

Unfortunately, since this is a network problem, there's not much we can do about this. The app needs to be able to connect to the Shopify to work.

I assume this isn't strictly a token exchange problem, but could you try setting unstable_newEmbeddedAuthStrategy: false in shopify.server.js? This will disable the token exchange strategy and revert back to redirecting the user to the install flow to get a token.

faner11 commented 6 months ago

This works for me by adding a proxy to the native fetch.

import { setGlobalDispatcher, ProxyAgent } from "undici";
import { env } from "process";

if (import.meta.env.DEV && env.https_proxy  ) {
  // Corporate proxy uses CA not in undici's certificate store
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
  const dispatcher = new ProxyAgen({uri: new URL(env.https_proxy).toString() });
  setGlobalDispatcher(dispatcher);
}
softlight0629 commented 6 months ago

@faner11 it works for me

772265646 commented 5 months ago

还没有解决办法吗

coderlinbb commented 5 months ago

还没有解决办法吗

参考这个翻墙就可以了 https://doc.boccc.co/zh/article/clash-for-windows-tun-a8cexo/

xigongdaEricyang commented 5 months ago

This works for me by adding a proxy to the native fetch.

import { setGlobalDispatcher, ProxyAgent } from "undici";
import { env } from "process";

if (import.meta.env.DEV && env.https_proxy  ) {
  // Corporate proxy uses CA not in undici's certificate store
  process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
  const dispatcher = new ProxyAgen({uri: new URL(env.https_proxy).toString() });
  setGlobalDispatcher(dispatcher);
}

Could you tell me what's the content of https_proxy ?

faner11 commented 5 months ago

@xigongdaEricyang 你这个问题太基础了,去google吧,如果嫌麻烦,可以付费问问题。wx: ZmhoaDIw (这是base 64,你需要先解码)

dydwgmcnl4241 commented 5 months ago

我curl 谷歌都是通的,但仍然遇到这个问题。

koaqiu commented 5 months ago

@xigongdaEricyang @772265646 最终解决方案就是 搞个速度快的VPN梯子,直接全局代理过去。然后就清爽了。 记住一定要用VPN模式的,什么http socket代理的 配置起来很麻烦--你无法保证某个组件访问网络的时候能一定是通过代理走!

@chenluhe 这问题其实可以结案了,网络问题导致。

xigongdaEricyang commented 5 months ago

@xigongdaEricyang @772265646 最终解决方案就是 搞个速度快的VPN梯子,直接全局代理过去。然后就清爽了。 记住一定要用VPN模式的,什么http socket代理的 配置起来很麻烦--你无法保证某个组件访问网络的时候能一定是通过代理走!

@chenluhe 这问题其实可以结案了,网络问题导致。

确实!我现在一键全代了,就好了,汗

18239388662 commented 5 months ago

done! 上面的都试过了, 就是梯子问题,实在不行就换梯子

anasdevv commented 1 month ago

why this issue is closed ? still getting this error │ [shopify-app/INFO] Authenticating admin request 16:27:15 │ remix │ [shopify-app/INFO] Authenticating admin request 16:27:15 │ remix │ [shopify-app/INFO] No valid session found 16:27:15 │ remix │ [shopify-app/INFO] Requesting offline access token 16:27:15 │ remix │ [shopify-app/INFO] No valid session found 16:27:15 │ remix │ [shopify-app/INFO] Requesting offline access token 16:27:15 │ remix │ error Response { 16:27:15 │ remix │ size: 0, 16:27:15 │ remix │ [Symbol(Body internals)]: { 16:27:15 │ remix │ body: null, 16:27:15 │ remix │ type: null, 16:27:15 │ remix │ size: 0, 16:27:15 │ remix │ boundary: null, 16:27:15 │ remix │ disturbed: false, 16:27:15 │ remix │ error: null 16:27:15 │ remix │ }, 16:27:15 │ remix │ [Symbol(Response internals)]: { 16:27:15 │ remix │ url: undefined, 16:27:15 │ remix │ status: 500, 16:27:15 │ remix │ statusText: 'Internal Server Error', 16:27:15 │ remix │ headers: {}, 16:27:15 │ remix │ counter: 0, 16:27:15 │ remix │ highWaterMark: undefined 16:27:15 │ remix │ } 16:27:15 │ remix │ }

yanyi24 commented 1 month ago

@xigongdaEricyang @772265646 最终解决方案就是 搞个速度快的VPN梯子,直接全局代理过去。然后就清爽了。 记住一定要用VPN模式的,什么http socket代理的 配置起来很麻烦--你无法保证某个组件访问网络的时候能一定是通过代理走! @chenluhe 这问题其实可以结案了,网络问题导致。

确实!我现在一键全代了,就好了,汗

你用的哪个梯子?