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
bug: useSuspenseQuery
will get "UNAUTHORIZED" tRPC error
#1765
Comments
Yup this is a limitation in Next since they don't provide any primitive to access headers from a client component during the SSR prepass phase, so queries made on the server wont be authed... You can fix this by prefetching the data in an RSC and hydrating the query client or pass the initial data as props. Unfortunately not much we can do here, there is a community package https://github.com/moshest/next-client-cookies that "hacks" around it although I've never tried it |
Any update or ways around this? Would be great to use useSuspenseQuery |
I use |
Provide environment information
System:
OS: macOS 14.2.1
CPU: (8) arm64 Apple M1 Pro
Memory: 196.13 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.9.0 - ~/.nvm/versions/node/v20.9.0/bin/node
Yarn: 1.22.21 - ~/.nvm/versions/node/v20.9.0/bin/yarn
npm: 10.1.0 - ~/.nvm/versions/node/v20.9.0/bin/npm
pnpm: 8.14.0 - ~/Library/pnpm/pnpm
Describe the bug
If we have a protected api like:
Then we use
useSuspenseQuery
We will get the error
UNAUTHORIZED
fromCleanShot.2024-02-19.at.17.54.35.mp4
You can check the detail of my code in this commit: Crayon-ShinChan/t3-trpc-suspense-bug@b747bba
Reproduction repo
https://github.com/Crayon-ShinChan/t3-trpc-suspense-bug
To reproduce
DISCORD_CLIENT_ID
,DISCORD_CLIENT_SECRET
to .env filepnpm dev
Additional information
No response
The text was updated successfully, but these errors were encountered: