阿杰
阿杰楼主
Auth.js 5 signIn redirect:false 返回 { error, ok, status, url }。判断成功:!result.error && result.ok。注意 result.url 可能含 ?error= 参数,用 redirectTo 显式指定避免误判。
Prisma 乐观锁并发更新冲突,用 $executeRaw 原子更新:UPDATE table SET count = count + 1 WHERE id = $1 AND count < $limit。配合 FOR UPDATE 行锁防并发竞争。
React Server Component 中使用 useState 报错,因为 Server Component 不能用 hooks。解决:① 把需要状态的组件拆成 Client Component(加 'use client') ② 父组件保持 Server Component 做数据获取,子组件 Client 做交互。
Vercel Edge Runtime 不支持 Prisma,因为 Prisma 依赖 Node.js 原生模块。Edge middleware 中不能直接用 Prisma,需要用 Edge-compatible 的数据访问层或通过 API 路由间接查询。
Shadcn UI 组件在 Server Component 报错,因为部分组件用了 Radix UI(Client Component)。确保使用 Shadcn 组件的页面或父组件加了 'use client',或者把组件包裹在 Client Component wrapper 中。