NextAuth集成Hasura报错:field 'accounts' not found in type: 'users_bool_exp'求助
问题:NextAuth Hasura适配器报错
field 'accounts' not found in type: 'users_bool_exp' 我按照NextAuth Hasura教程操作时,遇到以下错误:
message: `field 'accounts' not found in type: 'users_bool_exp':
请求日志及GraphQL错误详情:
POST /api/auth/signin/github 302 in 8ms [next-auth][error][adapter_error_getUserByAccount] https://next-auth.js.org/errors#adapter_error_getuserbyaccount field 'accounts' not found in type: 'users_bool_exp': {"response":{"errors":[{"message":"field 'accounts' not found in type: 'users_bool_exp'","extensions":{"path":"$.selectionSet.users.args.where.accounts","code":"validation-failed"}}],"status":200,"headers":{}},"request":{"query":"query GetUsers($where: users_bool_exp!) { users(where: $where) { ...User } } fragment User on users { __typename id name email image emailVerified }","variables":{"where":{"accounts":{"provider":{"_eq":"github"},"providerAccountId":{"_eq":"790821"}}}}}}
调用栈显示错误来自Hasura适配器:
' at makeRequest (\\node_modules\\graphql-request\\build\\cjs\\index.js:310:15)\n' + ' at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n' + ' at async getUserByAccount (\\node_modules\\next-auth-hasura-adapter\\dist\\index.js:46:25)', name: 'Error'
解决建议
这个错误的核心原因是Hasura中users表的过滤类型users_bool_exp不包含accounts字段,说明users与accounts表的关联关系未正确配置,或者权限未开放。按以下步骤排查:
- 登录Hasura控制台,进入Data页面,找到
users表 - 切换到Relationships标签,确认是否存在名为
accounts的关系:- 若不存在,点击「Add Relationship」,选择
accounts表,设置关联规则为users.id = accounts.user_id,命名为accounts
- 若不存在,点击「Add Relationship」,选择
- 切换到Permissions标签,找到NextAuth使用的数据库角色:
- 确保该角色对
users表有select权限 - 在「Row select permissions」中,允许使用
accounts字段进行过滤
- 确保该角色对
- 额外检查
accounts表结构:确认存在provider、providerAccountId、user_id字段,且user_id是关联users.id的外键
内容的提问来源于stack exchange,提问作者gyurisc
相关产品推荐
相关产品推荐

