using next.js +next-auth + Prisma + PostgreSQL
I added a custom login page and added the providers as well.
my userId in the database is Int so when I log in with credentials I have no issue but when logging in with one of the social providers I get an error…
Argument userId: Got invalid value '5106220' on Prisma.findManyTodos. Provided String, expected IntFilter or Int:
how to force providers to use Int instead of String when connecting to a database.
This error occurs whenever i need to connect the database
This is a Full error
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: '[email protected]',
picture: { data: [Object] }
}
}
[next-auth][debug][OAUTH_CALLBACK_RESPONSE] {
profile: {
id: '5062260',
name: ' Eco',
email: '[email protected]',
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: '[email protected]',
picture: { data: [Object] }
}
}
{
user: {
name: 'co',
email: '[email protected]',
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:UserselearDesktopTokTok4unode_modules@prismaclientruntimeindex.js:29297:20)
at serializationFn (C:UserselearDesktopTokTok4unode_modules@prismaclientruntimeindex.js:31876:19)
at runInChildSpan (C:UserselearDesktopTokTok4unode_modules@prismaclientruntimeindex.js:25100:12)
at PrismaClient._executeRequest (C:UserselearDesktopTokTok4unode_modules@prismaclientruntimeindex.js:31883:31)
at consumer (C:UserselearDesktopTokTok4unode_modules@prismaclientruntimeindex.js:31810:23)
at C:UserselearDesktopTokTok4unode_modules@prismaclientruntimeindex.js:31815:51
at AsyncResource.runInAsyncScope (node:async_hooks:201:9)
at C:UserselearDesktopTokTok4unode_modules@prismaclientruntimeindex.js:31815:29
at runInChildSpan (C:UserselearDesktopTokTok4unode_modules@prismaclientruntimeindex.js:25100:12)
at PrismaClient._request (C:UserselearDesktopTokTok4unode_modules@prismaclientruntimeindex.js:31812:22) {
clientVersion: '4.4.0'
}
API resolved without sending a response for /api/v1/todo/get, this may result in stalled requests.
3
Answers
According to the Prisma adapter in the NextAuth docs, the
User
model in the Prisma schema needs to have anid
field with aString
type.You must add + before the field.
Example +id or +productId and try again.
This helps me resolve my problem.
Changing only schema is not enough, solution should be to make your own adapter.
@next-auth/prisma-adapter
uses default Next-Auth’s model & schema, which declareid
as astring
type. This means that native adapter expects you to follow them and thus, types them as such and don’t convert provided strings as integers. Here you can check the structure of the native adapter.How I solved it
If you are using TypeScript you will have quite a time, it’s really painful to correctly type everything due to how strongly typed
DefaultAdapter
is. Types you would need to look in to areAdapter
,AdapterUser
andAdapterAccount
, all of which is insidenext-auth/adapters.d.ts