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

Request missing headers after error-handling through error page #14842

Closed
Kolobok12309 opened this issue Sep 8, 2022 · 6 comments
Closed

Request missing headers after error-handling through error page #14842

Kolobok12309 opened this issue Sep 8, 2022 · 6 comments

Comments

@Kolobok12309
Copy link
Contributor

Environment

Nuxt CLI v3.0.0-rc.4 10:33:52
RootDir: 10:33:53
Nuxt project info: 10:33:53


  • Operating System: Darwin
  • Node Version: v14.19.3
  • Nuxt Version: 3.0.0-rc.4
  • Package Manager: yarn@1.22.15
  • Builder: vite
  • User Config: alias, modules, css, build, vite
  • Runtime Modules: @pinia/nuxt@0.1.9, shared-front/nuxt/axios, shared-front/nuxt/cookies, shared-front/nuxt/registry, shared-front/nuxt/domain, shared-front/nuxt/theme, shared-front/nuxt/components, shared-front/nuxt/mq-handler
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-pgghw6

Describe the bug

After handling error, nitro make request to /__nuxt_error, but this request lost all headers, and ErrorPage cannot access them
https://github.com/nuxt/framework/blob/bb8942a401cef3d41c39e9d50e6630e766998c1c/packages/nuxt/src/core/runtime/nitro/error.ts#L47

Additional context

Fixed with this code

... $fetch(withQuery('/__nuxt_error', errorObject), {
  headers: event.req.headers,
}) ...

Logs

console.log from minimal-reproduce

app headers {
  accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
  connection: 'close',
  'content-length': '0',
  host: 'localhost:3000',
  origin: 'https://localhost:3000',
  referer: 'https://localhost:3000/',
  'sec-ch-ua': '"Chromium";v="104", " Not A;Brand";v="99", "Google Chrome";v="104"',
  'sec-ch-ua-mobile': '?0',
  'sec-ch-ua-platform': '"macOS"',
  'upgrade-insecure-requests': '1',
  'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36'
}
[Vue warn]: Unhandled error during execution of setup function 
  at <Error onVnodeUnmounted=fn<onVnodeUnmounted> ref=Ref< undefined > >
[nitro] [dev] [unhandledRejection] Error: some error
    at setup (/home/projects/github-pgghw6/pages/error.vue:6:7)
    at _sfc_main.setup (/home/projects/github-pgghw6/pages/error.vue:28:23)
    at callWithErrorHandling (/home/projects/github-pgghw6/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:157:22)
    at setupStatefulComponent (/home/projects/github-pgghw6/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7107:29)
    at setupComponent (/home/projects/github-pgghw6/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:7062:11)
    at renderComponentVNode (/home/projects/github-pgghw6/node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:172:17)
    at renderVNode (/home/projects/github-pgghw6/node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:295:22)
    at renderComponentSubTree (/home/projects/github-pgghw6/node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:259:13)
    at renderComponentVNode (/home/projects/github-pgghw6/node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:188:16)
    at renderVNode (/home/projects/github-pgghw6/node_modules/@vue/server-renderer/dist/server-renderer.cjs.js:295:22)
error headers { host: 'localhost' }
@danielroe
Copy link
Member

The middleware will be called the second time when rendering the error page. The headers, etc., are deliberately not present on this page so it can be cached. If you would like to render something on the error page dependent on user headers, then you should set it on the error object itself which can be passed to your custom error.vue file./

(see #14758)

cc: @pi0

@Kolobok12309
Copy link
Contributor Author

@danielroe How i can pass user Bearer token to error page, to render header like github and without caching token?

@Luffyyy
Copy link

Luffyyy commented Sep 8, 2022

#14780 sounds like my issue (close it and keep this one if it is). I believe this functionality should be optional in some way unless it's safe to pass headers to the error call 🤔 There are many cases we want to persist a user being logged in despite showing an error page it's really weird seeing the user not logged for a brief moment.

@senher
Copy link

senher commented Sep 20, 2022

#7174听起来像是我的问题(如果是,请关闭并保留此问题)。我相信这个功能在某种程度上应该是可选的,除非将标头传递给错误调用是安全的🤔在很多情况下,尽管显示了错误页面,但我们仍希望保持用户正在登录,看到用户在短时间内没有登录真的很奇怪。

#7669
yes i had the same problem
On error page refresh, pinia will not initialize, even if it's a simple 404 error
Did you find another solution?

@Luffyyy
Copy link

Luffyyy commented Sep 20, 2022

I hope that this issue will get some kind of solution, I think it's pretty important and hurts ux for users. A temporary solution would be welcome too, I personally haven't found a way to make it work unfortunately.

@pi0
Copy link
Member

pi0 commented Oct 19, 2022

With last RC.12 we explicitly disable cache for /__nuxt_error as caching was neither easy or good idea. Merging nuxt/framework#7340 to land in next release 👍🏼 (you can try on edge channel. please mention if still not passing correctly)

@pi0 pi0 closed this as completed Oct 19, 2022
@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe transferred this issue from nuxt/framework Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants