next-auth
next-auth copied to clipboard
Prisma + Slack fails on linkAccount
Title
Prisma + Slack fails on linkAccount
How to reproduce ☕️
Use prisma and slack in a project.
When trying to log in you should get an error like so...
Unknown arg
okin data.ok for type AccountUncheckedCreateInput. Did you meanid? Available args: type AccountUncheckedCreateInput { id?: String userId: String type: String provider: String providerAccountId: String refresh_token?: String | Null access_token?: String | Null expires_at?: Int | Null token_type?: String | Null scope?: String | Null id_token?: String | Null session_state?: String | Null oauth_token_secret?: String | Null oauth_token?: String | Null } Unknown argstatein data.state for type AccountUncheckedCreateInput. Did you meantype? Available args: type AccountUncheckedCreateInput { id?: String userId: String session_state?: String | Null oauth_token_secret?: String | Null oauth_token?: String | Null }
The reason this happens isn't any thing crazy-- the object that comes back from slack has two additional properties or so it appears. "ok" and "state". When linkAccount runs (which is a really basic method that doesn't remap any fields) it's got fields that prisma isn't expecting on the base schema.
linkAccount: (data) => p.account.create({ data }),
Your question/bug report 📓
See reproduction above.
Contributing 🙌🏽
No, I'm afraid I cannot help regarding this
I was able to hack around it by writing this...
const adapter = PrismaAdapter(prisma)
adapter.linkAccount = ({ provider, type, providerAccountId, access_token, token_type, id_token, userId }) => {
return prisma.account.create({ data:{
provider, type, providerAccountId, access_token, token_type, id_token, userId
} })
}
Side note, it might be worth using transactions if/when possible to avoid getting into a bad state. When I'm in this state, I can't get out of it.
Your "hack" would be the recommended way of doing it, although I might simplify it like so:
const adapter = {
...PrismaAdapter(prisma),
linkAccount: ({ ok, state, ...data }) => prisma.account.create({ data })
}
Another way to fix this would be to add the ok and state fields to your Account schema. We intentionally don't strip away anything from the incoming data.
It looks like though that now multiple Providers are returning fields that conflict with our default schemas.
Either we keep recommending to add notes to the Providers like this https://github.com/nextauthjs/docs/pull/79
or we could add an account callback to the core, or to the provider config (similar to profile):
https://next-auth.js.org/configuration/callbacks
https://next-auth.js.org/configuration/providers/oauth#options
nextauthjs/next-auth has been migrated to a monorepository. The adapters code can now be found there under packages/adapter-*. Thanks for your interest in the project!
Im having the same issue with github. from the example repo
Invalid `p.account.create()` invocation in
/Applications/MAMP/htdocs/PROJECTS2022/rest-nextjs-api-routes-auth/node_modules/@next-auth/prisma-adapter/dist/index.js:19:42
16 },
17 updateUser: (data) => p.user.update({ where: { id: data.id }, data }),
18 deleteUser: (id) => p.user.delete({ where: { id } }),
→ 19 linkAccount: (data) => p.account.create({
data: {
provider: 'github',
type: 'oauth',
providerAccountId: '681890',
access_token: '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',
~~~~~~~~~~~~
token_type: 'bearer',
~~~~~~~~~~
scope: 'read:user,user:email',
userId: 3
}
})
Unknown arg `access_token` in data.access_token for type AccountUncheckedCreateInput. Did you mean `accessToken`? Available args:
type AccountUncheckedCreateInput {
id?: Int
type: String
provider: String
providerAccountId: String
refreshToken?: String | Null
accessToken?: String | Null
expiresAt?: Int | Null
tokenType?: String | Null
scope?: String | Null
idToken?: String | Null
sessionState?: String | Null
oauthTokenSecret?: String | Null
oauthToken?: String | Null
userId: Int
}
Unknown arg `token_type` in data.token_type for type AccountUncheckedCreateInput. Did you mean `tokenType`? Available args:
type AccountUncheckedCreateInput {
id?: Int
type: String
provider: String
providerAccountId: String
refreshToken?: String | Null
accessToken?: String | Null
expiresAt?: Int | Null
tokenType?: String | Null
scope?: String | Null
idToken?: String | Null
sessionState?: String | Null
oauthTokenSecret?: String | Null
oauthToken?: String | Null
userId: Int
}
{
message: '\n' +
'Invalid `p.account.create()` invocation in\n' +
'/Applications/MAMP/htdocs/PROJECTS2022/rest-nextjs-api-routes-auth/node_modules/@next-auth/prisma-adapter/dist/index.js:19:42\n' +
'\n' +
' 16 },\n' +
' 17 updateUser: (data) => p.user.update({ where: { id: data.id }, data }),\n' +
' 18 deleteUser: (id) => p.user.delete({ where: { id } }),\n' +
'→ 19 linkAccount: (data) => p.account.create({\n' +
' data: {\n' +
" provider: 'github',\n" +
" type: 'oauth',\n" +
" providerAccountId: '681890',\n" +
" access_token: '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',\n" +
' ~~~~~~~~~~~~\n' +
" token_type: 'bearer',\n" +
' ~~~~~~~~~~\n' +
" scope: 'read:user,user:email',\n" +
' userId: 3\n' +
' }\n' +
' })\n' +
'\n' +
'Unknown arg `access_token` in data.access_token for type AccountUncheckedCreateInput. Did you mean `accessToken`? Available args:\n' +
'type AccountUncheckedCreateInput {\n' +
' id?: Int\n' +
' type: String\n' +
' provider: String\n' +
' providerAccountId: String\n' +
' refreshToken?: String | Null\n' +
' accessToken?: String | Null\n' +
' expiresAt?: Int | Null\n' +
' tokenType?: String | Null\n' +
' scope?: String | Null\n' +
' idToken?: String | Null\n' +
' sessionState?: String | Null\n' +
' oauthTokenSecret?: String | Null\n' +
' oauthToken?: String | Null\n' +
' userId: Int\n' +
'}\n' +
'Unknown arg `token_type` in data.token_type for type AccountUncheckedCreateInput. Did you mean `tokenType`? Available args:\n' +
'type AccountUncheckedCreateInput {\n' +
' id?: Int\n' +
' type: String\n' +
' provider: String\n' +
' providerAccountId: String\n' +
' refreshToken?: String | Null\n' +
' accessToken?: String | Null\n' +
' expiresAt?: Int | Null\n' +
' tokenType?: String | Null\n' +
' scope?: String | Null\n' +
' idToken?: String | Null\n' +
' sessionState?: String | Null\n' +
' oauthTokenSecret?: String | Null\n' +
' oauthToken?: String | Null\n' +
' userId: Int\n' +
'}\n' +
'\n',
stack: 'Error: \n' +
'Invalid `p.account.create()` invocation in\n' +
'/Applications/MAMP/htdocs/PROJECTS2022/rest-nextjs-api-routes-auth/node_modules/@next-auth/prisma-adapter/dist/index.js:19:42\n' +
'\n' +
' 16 },\n' +
' 17 updateUser: (data) => p.user.update({ where: { id: data.id }, data }),\n' +
' 18 deleteUser: (id) => p.user.delete({ where: { id } }),\n' +
'→ 19 linkAccount: (data) => p.account.create({\n' +
' data: {\n' +
" provider: 'github',\n" +
" type: 'oauth',\n" +
" providerAccountId: '681890',\n" +
" access_token: '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',\n" +
' ~~~~~~~~~~~~\n' +
" token_type: 'bearer',\n" +
' ~~~~~~~~~~\n' +
" scope: 'read:user,user:email',\n" +
' userId: 3\n' +
' }\n' +
' })\n' +
'\n' +
'Unknown arg `access_token` in data.access_token for type AccountUncheckedCreateInput. Did you mean `accessToken`? Available args:\n' +
'type AccountUncheckedCreateInput {\n' +
' id?: Int\n' +
' type: String\n' +
' provider: String\n' +
' providerAccountId: String\n' +
' refreshToken?: String | Null\n' +
' accessToken?: String | Null\n' +
' expiresAt?: Int | Null\n' +
' tokenType?: String | Null\n' +
' scope?: String | Null\n' +
' idToken?: String | Null\n' +
' sessionState?: String | Null\n' +
' oauthTokenSecret?: String | Null\n' +
' oauthToken?: String | Null\n' +
' userId: Int\n' +
'}\n' +
'Unknown arg `token_type` in data.token_type for type AccountUncheckedCreateInput. Did you mean `tokenType`? Available args:\n' +
'type AccountUncheckedCreateInput {\n' +
' id?: Int\n' +
' type: String\n' +
' provider: String\n' +
' providerAccountId: String\n' +
' refreshToken?: String | Null\n' +
' accessToken?: String | Null\n' +
' expiresAt?: Int | Null\n' +
' tokenType?: String | Null\n' +
' scope?: String | Null\n' +
' idToken?: String | Null\n' +
' sessionState?: String | Null\n' +
' oauthTokenSecret?: String | Null\n' +
' oauthToken?: String | Null\n' +
' userId: Int\n' +
'}\n' +
'\n' +
'\n' +
' at Object.validate (/Applications/MAMP/htdocs/PROJECTS2022/rest-nextjs-api-routes-auth/node_modules/@prisma/client/runtime/index.js:34786:20)\n' +
' at PrismaClient._executeRequest (/Applications/MAMP/htdocs/PROJECTS2022/rest-nextjs-api-routes-auth/node_modules/@prisma/client/runtime/index.js:40911:17)\n' +
' at consumer (/Applications/MAMP/htdocs/PROJECTS2022/rest-nextjs-api-routes-auth/node_modules/@prisma/client/runtime/index.js:40856:23)\n' +
' at /Applications/MAMP/htdocs/PROJECTS2022/rest-nextjs-api-routes-auth/node_modules/@prisma/client/runtime/index.js:40860:76\n' +
' at runInChildSpan (/Applications/MAMP/htdocs/PROJECTS2022/rest-nextjs-api-routes-auth/node_modules/@prisma/client/runtime/index.js:39945:12)\n' +
' at /Applications/MAMP/htdocs/PROJECTS2022/rest-nextjs-api-routes-auth/node_modules/@prisma/client/runtime/index.js:40860:20\n' +
' at AsyncResource.runInAsyncScope (async_hooks.js:197:9)\n' +
' at PrismaClient._request (/Applications/MAMP/htdocs/PROJECTS2022/rest-nextjs-api-routes-auth/node_modules/@prisma/client/runtime/index.js:40859:86)\n' +
' at /Applications/MAMP/htdocs/PROJECTS2022/rest-nextjs-api-routes-auth/node_modules/@prisma/client/runtime/index.js:40190:25\n' +
' at _callback (/Applications/MAMP/htdocs/PROJECTS2022/rest-nextjs-api-routes-auth/node_modules/@prisma/client/runtime/index.js:39960:52)',
name: 'Error'
}
Im having the same issue with github. from the example repo
Invalid `p.account.create()` invocation in /Applications/MAMP/htdocs/PROJECTS2022/rest-nextjs-api-routes-auth/node_modules/@next-auth/prisma-adapter/dist/index.js:19:42 16 }, 17 updateUser: (data) => p.user.update({ where: { id: data.id }, data }), 18 deleteUser: (id) => p.user.delete({ where: { id } }), → 19 linkAccount: (data) => p.account.create({ data: { provider: 'github', type: 'oauth', providerAccountId: '681890', access_token: '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', ~~~~~~~~~~~~ token_type: 'bearer', ~~~~~~~~~~ scope: 'read:user,user:email', userId: 3 } }) Unknown arg `access_token` in data.access_token for type AccountUncheckedCreateInput. Did you mean `accessToken`? Available args: type AccountUncheckedCreateInput { id?: Int type: String provider: String providerAccountId: String refreshToken?: String | Null accessToken?: String | Null expiresAt?: Int | Null tokenType?: String | Null scope?: String | Null idToken?: String | Null sessionState?: String | Null oauthTokenSecret?: String | Null oauthToken?: String | Null userId: Int } Unknown arg `token_type` in data.token_type for type AccountUncheckedCreateInput. Did you mean `tokenType`? Available args: type AccountUncheckedCreateInput { id?: Int type: String provider: String providerAccountId: String refreshToken?: String | Null accessToken?: String | Null expiresAt?: Int | Null tokenType?: String | Null scope?: String | Null idToken?: String | Null sessionState?: String | Null oauthTokenSecret?: String | Null oauthToken?: String | Null userId: Int } { message: '\n' + 'Invalid `p.account.create()` invocation in\n' + '/Applications/MAMP/htdocs/PROJECTS2022/rest-nextjs-api-routes-auth/node_modules/@next-auth/prisma-adapter/dist/index.js:19:42\n' + '\n' + ' 16 },\n' + ' 17 updateUser: (data) => p.user.update({ where: { id: data.id }, data }),\n' + ' 18 deleteUser: (id) => p.user.delete({ where: { id } }),\n' + '→ 19 linkAccount: (data) => p.account.create({\n' + ' data: {\n' + " provider: 'github',\n" + " type: 'oauth',\n" + " providerAccountId: '681890',\n" + " access_token: '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',\n" + ' ~~~~~~~~~~~~\n' + " token_type: 'bearer',\n" + ' ~~~~~~~~~~\n' + " scope: 'read:user,user:email',\n" + ' userId: 3\n' + ' }\n' + ' })\n' + '\n' + 'Unknown arg `access_token` in data.access_token for type AccountUncheckedCreateInput. Did you mean `accessToken`? Available args:\n' + 'type AccountUncheckedCreateInput {\n' + ' id?: Int\n' + ' type: String\n' + ' provider: String\n' + ' providerAccountId: String\n' + ' refreshToken?: String | Null\n' + ' accessToken?: String | Null\n' + ' expiresAt?: Int | Null\n' + ' tokenType?: String | Null\n' + ' scope?: String | Null\n' + ' idToken?: String | Null\n' + ' sessionState?: String | Null\n' + ' oauthTokenSecret?: String | Null\n' + ' oauthToken?: String | Null\n' + ' userId: Int\n' + '}\n' + 'Unknown arg `token_type` in data.token_type for type AccountUncheckedCreateInput. Did you mean `tokenType`? Available args:\n' + 'type AccountUncheckedCreateInput {\n' + ' id?: Int\n' + ' type: String\n' + ' provider: String\n' + ' providerAccountId: String\n' + ' refreshToken?: String | Null\n' + ' accessToken?: String | Null\n' + ' expiresAt?: Int | Null\n' + ' tokenType?: String | Null\n' + ' scope?: String | Null\n' + ' idToken?: String | Null\n' + ' sessionState?: String | Null\n' + ' oauthTokenSecret?: String | Null\n' + ' oauthToken?: String | Null\n' + ' userId: Int\n' + '}\n' + '\n', stack: 'Error: \n' + 'Invalid `p.account.create()` invocation in\n' + '/Applications/MAMP/htdocs/PROJECTS2022/rest-nextjs-api-routes-auth/node_modules/@next-auth/prisma-adapter/dist/index.js:19:42\n' + '\n' + ' 16 },\n' + ' 17 updateUser: (data) => p.user.update({ where: { id: data.id }, data }),\n' + ' 18 deleteUser: (id) => p.user.delete({ where: { id } }),\n' + '→ 19 linkAccount: (data) => p.account.create({\n' + ' data: {\n' + " provider: 'github',\n" + " type: 'oauth',\n" + " providerAccountId: '681890',\n" + " access_token: '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',\n" + ' ~~~~~~~~~~~~\n' + " token_type: 'bearer',\n" + ' ~~~~~~~~~~\n' + " scope: 'read:user,user:email',\n" + ' userId: 3\n' + ' }\n' + ' })\n' + '\n' + 'Unknown arg `access_token` in data.access_token for type AccountUncheckedCreateInput. Did you mean `accessToken`? Available args:\n' + 'type AccountUncheckedCreateInput {\n' + ' id?: Int\n' + ' type: String\n' + ' provider: String\n' + ' providerAccountId: String\n' + ' refreshToken?: String | Null\n' + ' accessToken?: String | Null\n' + ' expiresAt?: Int | Null\n' + ' tokenType?: String | Null\n' + ' scope?: String | Null\n' + ' idToken?: String | Null\n' + ' sessionState?: String | Null\n' + ' oauthTokenSecret?: String | Null\n' + ' oauthToken?: String | Null\n' + ' userId: Int\n' + '}\n' + 'Unknown arg `token_type` in data.token_type for type AccountUncheckedCreateInput. Did you mean `tokenType`? Available args:\n' + 'type AccountUncheckedCreateInput {\n' + ' id?: Int\n' + ' type: String\n' + ' provider: String\n' + ' providerAccountId: String\n' + ' refreshToken?: String | Null\n' + ' accessToken?: String | Null\n' + ' expiresAt?: Int | Null\n' + ' tokenType?: String | Null\n' + ' scope?: String | Null\n' + ' idToken?: String | Null\n' + ' sessionState?: String | Null\n' + ' oauthTokenSecret?: String | Null\n' + ' oauthToken?: String | Null\n' + ' userId: Int\n' + '}\n' + '\n' + '\n' + ' at Object.validate (/Applications/MAMP/htdocs/PROJECTS2022/rest-nextjs-api-routes-auth/node_modules/@prisma/client/runtime/index.js:34786:20)\n' + ' at PrismaClient._executeRequest (/Applications/MAMP/htdocs/PROJECTS2022/rest-nextjs-api-routes-auth/node_modules/@prisma/client/runtime/index.js:40911:17)\n' + ' at consumer (/Applications/MAMP/htdocs/PROJECTS2022/rest-nextjs-api-routes-auth/node_modules/@prisma/client/runtime/index.js:40856:23)\n' + ' at /Applications/MAMP/htdocs/PROJECTS2022/rest-nextjs-api-routes-auth/node_modules/@prisma/client/runtime/index.js:40860:76\n' + ' at runInChildSpan (/Applications/MAMP/htdocs/PROJECTS2022/rest-nextjs-api-routes-auth/node_modules/@prisma/client/runtime/index.js:39945:12)\n' + ' at /Applications/MAMP/htdocs/PROJECTS2022/rest-nextjs-api-routes-auth/node_modules/@prisma/client/runtime/index.js:40860:20\n' + ' at AsyncResource.runInAsyncScope (async_hooks.js:197:9)\n' + ' at PrismaClient._request (/Applications/MAMP/htdocs/PROJECTS2022/rest-nextjs-api-routes-auth/node_modules/@prisma/client/runtime/index.js:40859:86)\n' + ' at /Applications/MAMP/htdocs/PROJECTS2022/rest-nextjs-api-routes-auth/node_modules/@prisma/client/runtime/index.js:40190:25\n' + ' at _callback (/Applications/MAMP/htdocs/PROJECTS2022/rest-nextjs-api-routes-auth/node_modules/@prisma/client/runtime/index.js:39960:52)', name: 'Error' }
This looks like a different error btw. You just don't have the fields access_token and token_type in your prisma schema. And that's correct..
The token_type should be tokenType and access_token accessToken based on the available schema output in the error msg. Read it more carefully next time, prisma usually tells you exactly what's wrong 😉👍
You just don't have the fields access_token and token_type in your prisma schema. And that's correct.. @ndom91 Im using the schema in the github repo for the example. How do I fix this?
model Account {
id Int @id @default(autoincrement())
type String
provider String
providerAccountId String
refreshToken String? @map("refresh_token")
accessToken String? @map("access_token")
expiresAt Int? @map("expires_at")
tokenType String? @map("token_type")
scope String?
idToken String?
sessionState String? @map("session_state")
oauthTokenSecret String? @map("oauth_token_secret")
oauthToken String? @map("oauth_token")
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int
@@unique([provider, providerAccountId])
}
@webface If thats the schema you've used, then the accessToken field, for example, should have been available via access_token due to your @map("access_token") mapping.
Give reapplying that schema a shot (prisma migrate)
Greetings! I just stumbled across the same issue @webface described and decided to write this comment here. I've noticed that mapping fields like access_token and token_type will raise an error when trying to sign in (I've also configured GitHub as a provider).
🟨 (1) Raises an error (Unknown arg `access_token` in data.access_token for type AccountUncheckedCreateInput. Did you mean `accessToken`?)
model Account {
...
accessToken String? @map("access_token") @db.Text
tokenType String? @map("token_type")
...
}
🟩 (2) Works just fine
model Account {
...
access_token String? @db.Text
token_type String?
...
}
I've double checked my DB and even though the column is, for example, access_token (configured as per example 1), the sign in fails. I guess I'll go without the mapping for now. Thank you for your work!
It looks like this issue did not receive any activity for 60 days. It will be closed in 7 days if no further activity occurs. If you think your issue is still relevant, commenting will keep it open. Thanks!
To keep things tidy, we are closing this issue for now. If you think your issue is still relevant, leave a comment and we might reopen it. Thanks!