【问题标题】:Argument userId: Got invalid value '5106220' on Prisma.findManyTodos. Provided String, expected IntFilter or Int:参数 userId:在 Prisma.findManyTodos 上获得无效值 \'5106220\'。提供的字符串,预期的 IntFilter 或 Int:
【发布时间】:2023-01-05 11:23:07
【问题描述】:

使用 next.js +next-auth + Prisma + PostgreSQL 我添加了一个自定义登录页面并添加了提供商。 我在数据库中的 userId 是 Int 所以当我使用凭据登录时我没有问题但是当使用其中一个社交提供商登录时我收到错误...

Argument userId: Got invalid value '5106220' on Prisma.findManyTodos. Provided String, expected IntFilter or Int:

如何强制提供程序在连接到数据库时使用 Int 而不是 String。 每当我需要连接数据库时都会出现此错误 这是一个完整的错误

provider: {
id: 'facebook',
name: 'Facebook',
type: 'oauth',
authorization: {
  url: 'https://www.facebook.com/v11.0/dialog/oauth',
  params: [Object]
},
token: {
  url: 'https://graph.facebook.com/oauth/access_token',
  params: {}
},
userinfo: {
  url: 'https://graph.facebook.com/me',
  params: [Object],
  request: [AsyncFunction: request]
},
profile: [Function: profile],
idToken: false,
checks: [ 'state' ],
clientId: 'MyClientId',
clientSecret: '413db228b5b8e2e1134f5',
signinUrl: 'http://localhost:3000/api/auth/signin/facebook',
callbackUrl: 'http://localhost:3000/api/auth/callback/facebook'


 }
}

[next-auth][debug][PROFILE_DATA] {
  OAuthProfile: {
    id: '11062270',
    name: 'obi ',
    email: 'ow1@gmail.com',
    picture: { data: [Object] }
  }
}
[next-auth][debug][OAUTH_CALLBACK_RESPONSE] {
  profile: {
    id: '5062260',
    name: ' Eco',
    email: 'ow1@gmail.com',
    image: 'https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=570&height=50&width=50&e&hash=AeR6hTT03RbzF9Z9hkg'
  },
  account: {
    provider: 'facebook',
    type: 'oauth',
    providerAccountId: '0711062270',
    access_token: 'EAAVmjxtUcOMBACPeAQm3Ocb0zzKcl8uiZAnZCYhhYxGo',
    token_type: 'bearer',
    expires_at: 1669548134
  },
  OAuthProfile: {
    id: '560',
    name: 'co',
    email: 'ow1@gmail.com',
    picture: { data: [Object] }
  }
}
{
  user: {
    name: 'co',
    email: 'ow1@gmail.com',
    image: 'https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=5007110622680570&height=50&width=50&ext=1666977090&hash=AeR6hTT03RbzF9Z9hkg',
    id: '106226'
  },
  expires: '2022-10-28T17:11:31.515Z',
  id: '1062'
}
PrismaClientValidationError: 
Invalid `prisma.todos.findMany()` invocation:

{
  where: {
    userId: '7110620'
            ~~~~~~~~~~~~~~~~~~
  },
  select: {
    id: true,
    text: true,
    done: true
  }
}

Argument userId: Got invalid value '5106220' on prisma.findManyTodos. Provided String, expected IntFilter or Int:
type IntFilter {
  equals?: Int
  in?: List<Int>
  notIn?: List<Int>
  lt?: Int
  lte?: Int
  gt?: Int
  gte?: Int
  not?: Int | NestedIntFilter
}
type IntFilter {
  equals?: Int
  in?: List<Int>
  notIn?: List<Int>
  lt?: Int
  lte?: Int
  gt?: Int
  gte?: Int
  not?: Int | NestedIntFilter
}


    at Document.validate (C:\Users\elear\Desktop\TokTok4u\node_modules\@prisma\client\runtime\index.js:29297:20)
    at serializationFn (C:\Users\elear\Desktop\TokTok4u\node_modules\@prisma\client\runtime\index.js:31876:19)
    at runInChildSpan (C:\Users\elear\Desktop\TokTok4u\node_modules\@prisma\client\runtime\index.js:25100:12)
    at PrismaClient._executeRequest (C:\Users\elear\Desktop\TokTok4u\node_modules\@prisma\client\runtime\index.js:31883:31)
    at consumer (C:\Users\elear\Desktop\TokTok4u\node_modules\@prisma\client\runtime\index.js:31810:23)
    at C:\Users\elear\Desktop\TokTok4u\node_modules\@prisma\client\runtime\index.js:31815:51
    at AsyncResource.runInAsyncScope (node:async_hooks:201:9)
    at C:\Users\elear\Desktop\TokTok4u\node_modules\@prisma\client\runtime\index.js:31815:29
    at runInChildSpan (C:\Users\elear\Desktop\TokTok4u\node_modules\@prisma\client\runtime\index.js:25100:12)
    at PrismaClient._request (C:\Users\elear\Desktop\TokTok4u\node_modules\@prisma\client\runtime\index.js:31812:22) {
  clientVersion: '4.4.0'
}
API resolved without sending a response for /api/v1/todo/get, this may result in stalled requests.

【问题讨论】:

    标签: next.js prisma next-auth


    【解决方案1】:

    根据 Prisma adapter in the NextAuth docs,Prisma 模式中的 User 模型需要有一个 id 字段和 String 类型。

    【讨论】:

    • 我知道使用 INT VS STRING 有很多方面。但是我的应用程序处于高级状态,它是基于 id as Int 构建的。所以我正在寻找是否有可能在 prismaClient 之前转换为 id 只有社交提供者
    • this page * ` 解释了 id Int 的 prisma.schema`
    【解决方案2】:

    你必须添加+场前。

    例子+编号要么+产品编号然后再试一次。

    这有助于我解决我的问题。

    【讨论】:

      猜你喜欢
      • 2021-11-28
      • 2019-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-17
      • 2017-09-11
      • 2018-12-27
      相关资源
      最近更新 更多