如何从 trpc.authCallback.useQuery() 获取成功的身份验证回调消息? (反应查询 v5 2024)

问题描述 投票:0回答:1

我一直在尝试从 Josh Tried Coding 构建一个 chatPDF 项目 - 在 youtube 上

https://www.youtube.com/watch?v=ztBJqzBU5kc&t=7558s)。我的问题从 2:06:00 开始,当时 page.tsx 文档中的 useQuery() 函数对我不起作用,因为它说没有重载与此调用匹配。 然后我研究发现,根据最新的React查询版本(v5),onSuccess和onError已被弃用。

然后我读了另一篇 stackoverflow 帖子,其中有人建议使用 isSuccess 和 isError,所以我就这样做了。

但是当我在 localhost:3000/auth-callback 上检查 Element 时,我仍然没有获得成功的 authcallback。 (参考下图) [here is the workaround code that i implemented]

[here is the error message on Inspect Element]

another picture of the error i received

error message received

[this is what i expected to see on my network window]

[this is the code that i found in the tutorial, which was using v4 of react query]

请指导我我必须做什么。谢谢...

typescript react-query trpc.io
1个回答
0
投票

您似乎有两个问题,一个与服务器的 401 未经授权有关,另一个与删除

onSuccess
/
onError
回调有关。

onSuccess
/
onError
回调在您收到服务器的响应后控制应用程序行为,并且它们依赖于该响应。
onSuccess
/
onError
不影响响应。 如图像所示,您收到 401 Unauthorized,而不是所需的 200 OK。从提供的代码中无法说出根本原因是什么。

另一方面,删除

onSuccess
/
onError
的解决方案看起来不错,但你可能应该将它们包裹在
useEffect
中。

这里有一篇博客文章解释了 TanStack Query v5 中的新 API。 https://tkdodo.eu/blog/breaking-react-querys-api-on- Purpose

© www.soinside.com 2019 - 2024. All rights reserved.