我在 Prisma Adapter 开启的情况下使用 Next Auth 时遇到错误我在create-t3-app。我成功在 Planetscale 数据库中添加了数据。
\n当我尝试使用 Next Auth Google Provider登录时出现此错误。还有Discord Provider,我可以登录并创建帐户以及链接到该帐户的用户。由于以下错误,我无法使用 Google 创建帐户。
\nprisma:query BEGIN\nprisma:query INSERT INTO `foo`.`Account` (`id`,`userId`,`type`,`provider`,`providerAccountId`,`access_token`,`expires_at`,`token_type`,`scope`,`id_token`) VALUES (?,?,?,?,?,?,?,?,?,?)\nprisma:query ROLLBACK\nprisma:error\nInvalid `p.account.create()` invocation in\n~/node_modules/@next-auth/prisma-adapter/dist/index.js:19:42\n\n 16 },\n 17 updateUser: ({ id, ...data }) => p.user.update({ where: { id }, data }),\n 18 deleteUser: (id) => p.user.delete({ where: { id } }),\n\xe2\x86\x92 19 linkAccount: (data) => p.account.create(\nThe provided value for the column is too long for the column\'s type. Column: …Run Code Online (Sandbox Code Playgroud) 目前,我的代码如下所示。当突变成功时,我必须重新获取所有数据,因为tasks不会更新。tasks提交或删除任务时如何更新客户端?
const { data: sessionData } = useSession()
const {
data: tasks,
refetch: refetchTasks,
} = api.task.getAll.useQuery(undefined, {
enabled: sessionData?.user !== undefined,
})
const createTask = api.task.create.useMutation({
onSuccess: async () => await refetchTasks(),
})
const createTaskValues = (values: { title: string }) =>
createTask.mutate({ title: values.title })
const deleteTask = api.task.delete.useMutation({
onSuccess: async () => await refetchTasks(),
})
Run Code Online (Sandbox Code Playgroud)
聚苯乙烯
useContext()除非你想每次都重新获取数据,否则使用比调用 refetch 函数更好。
const utils = api.useContext()
const createTask = api.task.create.useMutation({
onSuccess: () => utils.task.getAll.invalidate()
}) …Run Code Online (Sandbox Code Playgroud) api ×1
google-oauth ×1
next-auth ×1
oauth ×1
oauth-2.0 ×1
prisma ×1
react-query ×1
reactjs ×1
trpc.io ×1
typescript ×1