Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: schema.prisma #18

Open
wants to merge 2 commits into
base: completed
Choose a base branch
from

Conversation

cansurer-at
Copy link

@cansurer-at cansurer-at commented Sep 21, 2023

I had a problem with prisma schema and took 2 days to solve it. Basically i was not able to login with google auth. I get below error. I fix it via below issue on github and I just want to calobrate with solution.

nextauthjs/next-auth#3815

please do not forget to execute below code after you change your schema.prisma file

npx prisma db push

file should be like below:

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}

model User {
id String @id @default(uuid()) @Map("_id")
name String
email String @unique
emailVerified DateTime? @Map("email_verified")
image String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
accounts Account[]
sessions Session[]
Post Post[]
Comment Comment[]

@@Map("users")
}

model Account {
id String @id @default(cuid()) @Map("_id")
userId String @Map("user_id")
type String?
provider String
providerAccountId String @Map("provider_account_id")
token_type String?
refresh_token String?
access_token String?
expires_at Int?
scope String?
id_token String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)

@@unique([provider, providerAccountId])
@@Map("accounts")
}

model Session {
id String @id @default(cuid()) @Map("_id")
userId String? @Map("user_id")
sessionToken String @unique @Map("session_token")
accessToken String? @Map("access_token")
expires DateTime
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

@@Map("sessions")
}

model VerificationRequest {
id String @id @default(cuid()) @Map("_id")
identifier String
token String @unique
expires DateTime
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

@@unique([identifier, token])
}

model Category {
id String @id @default(cuid()) @Map("_id")
slug String @unique
title String
img String?
Posts Post[]
}

model Post {
id String @id @default(cuid()) @Map("_id")
createdAt DateTime @default(now())
slug String @unique
title String
desc String
img String?
views Int @default(0)
catSlug String
cat Category @relation(fields: [catSlug], references: [slug])
userEmail String
user User @relation(fields: [userEmail], references: [email])
comments Comment[]
}

model Comment {
id String @id @default(cuid()) @Map("_id")
createdAt DateTime @default(now())
desc String
userEmail String
user User @relation(fields: [userEmail], references: [email])
postSlug String
post Post @relation(fields: [postSlug], references: [slug])
}

ERROR :

[next-auth][warn][NEXTAUTH_URL]
https://next-auth.js.org/warnings#nextauth_url
[next-auth][error][adapter_error_getUserByAccount]
https://next-auth.js.org/errors#adapter_error_getuserbyaccount
Invalid prisma.account.findUnique() invocation:

{
where: {
provider_providerAccountId: {
~~~~~~~~~~~~~~~~~~~~~~~~~~
providerAccountId: "secret",
provider: "google"
},
? id?: String,
? providerId_providerAccountId?: AccountProviderIdProviderAccountIdCompoundUniqueInput,
? AND?: AccountWhereInput | AccountWhereInput[],
? OR?: AccountWhereInput[],
? NOT?: AccountWhereInput | AccountWhereInput[],
? userId?: StringFilter | String,
? providerType?: StringFilter | String,
? providerId?: StringFilter | String,
? providerAccountId?: StringFilter | String,
? refreshToken?: StringNullableFilter | String | Null,
? accessToken?: StringNullableFilter | String | Null,
? accessTokenExpires?: DateTimeNullableFilter | DateTime | Null,
? createdAt?: DateTimeFilter | DateTime,
? updatedAt?: DateTimeFilter | DateTime,
? user?: UserRelationFilter | UserWhereInput
},
select: {
user: true
}
}

Unknown argument provider_providerAccountId. Did you mean providerId_providerAccountId? Available options are listed in green. {
message: '\n' +
'Invalid prisma.account.findUnique() invocation:\n' +
'\n' +
'{\n' +
' where: {\n' +
' provider_providerAccountId: {\n' +
' ~~~~~~~~~~~~~~~~~~~~~~~~~~\n' +
' providerAccountId: "secret",\n' +
' provider: "google"\n' +
' },\n' +
'? id?: String,\n' +
'? providerId_providerAccountId?: AccountProviderIdProviderAccountIdCompoundUniqueInput,\n' +
'? AND?: AccountWhereInput | AccountWhereInput[],\n' +
'? OR?: AccountWhereInput[],\n' +
'? NOT?: AccountWhereInput | AccountWhereInput[],\n' +
'? userId?: StringFilter | String,\n' +
'? providerType?: StringFilter | String,\n' +
'? providerId?: StringFilter | String,\n' +
'? providerAccountId?: StringFilter | String,\n' +
'? refreshToken?: StringNullableFilter | String | Null,\n' +
'? accessToken?: StringNullableFilter | String | Null,\n' +
'? accessTokenExpires?: DateTimeNullableFilter | DateTime | Null,\n' +
'? createdAt?: DateTimeFilter | DateTime,\n' +
'? updatedAt?: DateTimeFilter | DateTime,\n' +
'? user?: UserRelationFilter | UserWhereInput\n' +
' },\n' +
' select: {\n' +
' user: true\n' +
' }\n' +
'}\n' +
'\n' +
'Unknown argument provider_providerAccountId. Did you mean providerId_providerAccountId? Available options are listed in green.',
stack: 'PrismaClientValidationError: \n' +
'Invalid prisma.account.findUnique() invocation:\n' +
'\n' +
'{\n' +
' where: {\n' +
' provider_providerAccountId: {\n' +
' ~~~~~~~~~~~~~~~~~~~~~~~~~~\n' +
' providerAccountId: "secret",\n' +
' provider: "google"\n' +
' },\n' +
'? id?: String,\n' +
'? providerId_providerAccountId?: AccountProviderIdProviderAccountIdCompoundUniqueInput,\n' +
'? AND?: AccountWhereInput | AccountWhereInput[],\n' +
'? OR?: AccountWhereInput[],\n' +
'? NOT?: AccountWhereInput | AccountWhereInput[],\n' +
'? userId?: StringFilter | String,\n' +
'? providerType?: StringFilter | String,\n' +
'? providerId?: StringFilter | String,\n' +
'? providerAccountId?: StringFilter | String,\n' +
'? refreshToken?: StringNullableFilter | String | Null,\n' +
'? accessToken?: StringNullableFilter | String | Null,\n' +
'? accessTokenExpires?: DateTimeNullableFilter | DateTime | Null,\n' +
'? createdAt?: DateTimeFilter | DateTime,\n' +
'? updatedAt?: DateTimeFilter | DateTime,\n' +
'? user?: UserRelationFilter | UserWhereInput\n' +
' },\n' +
' select: {\n' +
' user: true\n' +
' }\n' +
'}\n' +
'\n' +
'Unknown argument provider_providerAccountId. Did you mean providerId_providerAccountId? Available options are listed in green.\n' +
' at yn (/Users/cansurer/Documents/dev-workspace/next-react-blog/node_modules/@prisma/client/runtime/library.js:116:5852)\n' +
' at wn.handleRequestError (/Users/cansurer/Documents/dev-workspace/next-react-blog/node_modules/@prisma/client/runtime/library.js:123:6429)\n' +
' at wn.handleAndLogRequestError (/Users/cansurer/Documents/dev-workspace/next-react-blog/node_modules/@prisma/client/runtime/library.js:123:6119)\n' +
' at wn.request (/Users/cansurer/Documents/dev-workspace/next-react-blog/node_modules/@prisma/client/runtime/library.js:123:5839)\n' +
' at async l (/Users/cansurer/Documents/dev-workspace/next-react-blog/node_modules/@prisma/client/runtime/library.js:128:9763)\n' +
' at async getUserByAccount (webpack-internal:///(rsc)/./node_modules/@auth/prisma-adapter/index.js:220:29)',
name: 'PrismaClientValidationError'
}
[next-auth][error][OAUTH_CALLBACK_HANDLER_ERROR]
https://next-auth.js.org/errors#oauth_callback_handler_error
Invalid prisma.account.findUnique() invocation:

{
where: {
provider_providerAccountId: {
~~~~~~~~~~~~~~~~~~~~~~~~~~
providerAccountId: "101939472610204082780",
provider: "google"
},
? id?: String,
? providerId_providerAccountId?: AccountProviderIdProviderAccountIdCompoundUniqueInput,
? AND?: AccountWhereInput | AccountWhereInput[],
? OR?: AccountWhereInput[],
? NOT?: AccountWhereInput | AccountWhereInput[],
? userId?: StringFilter | String,
? providerType?: StringFilter | String,
? providerId?: StringFilter | String,
? providerAccountId?: StringFilter | String,
? refreshToken?: StringNullableFilter | String | Null,
? accessToken?: StringNullableFilter | String | Null,
? accessTokenExpires?: DateTimeNullableFilter | DateTime | Null,
? createdAt?: DateTimeFilter | DateTime,
? updatedAt?: DateTimeFilter | DateTime,
? user?: UserRelationFilter | UserWhereInput
},
select: {
user: true
}
}

Unknown argument provider_providerAccountId. Did you mean providerId_providerAccountId? Available options are listed in green. PrismaClientValidationError:
Invalid prisma.account.findUnique() invocation:

{
where: {
provider_providerAccountId: {
~~~~~~~~~~~~~~~~~~~~~~~~~~
providerAccountId: "secret",
provider: "google"
},
? id?: String,
? providerId_providerAccountId?: AccountProviderIdProviderAccountIdCompoundUniqueInput,
? AND?: AccountWhereInput | AccountWhereInput[],
? OR?: AccountWhereInput[],
? NOT?: AccountWhereInput | AccountWhereInput[],
? userId?: StringFilter | String,
? providerType?: StringFilter | String,
? providerId?: StringFilter | String,
? providerAccountId?: StringFilter | String,
? refreshToken?: StringNullableFilter | String | Null,
? accessToken?: StringNullableFilter | String | Null,
? accessTokenExpires?: DateTimeNullableFilter | DateTime | Null,
? createdAt?: DateTimeFilter | DateTime,
? updatedAt?: DateTimeFilter | DateTime,
? user?: UserRelationFilter | UserWhereInput
},
select: {
user: true
}
}

Unknown argument provider_providerAccountId. Did you mean providerId_providerAccountId? Available options are listed in green.
at yn (/Users/cansurer/Documents/dev-workspace/next-react-blog/node_modules/@prisma/client/runtime/library.js:116:5852)
at wn.handleRequestError (/Users/cansurer/Documents/dev-workspace/next-react-blog/node_modules/@prisma/client/runtime/library.js:123:6429)
at wn.handleAndLogRequestError (/Users/cansurer/Documents/dev-workspace/next-react-blog/node_modules/@prisma/client/runtime/library.js:123:6119)
at wn.request (/Users/cansurer/Documents/dev-workspace/next-react-blog/node_modules/@prisma/client/runtime/library.js:123:5839)
at async l (/Users/cansurer/Documents/dev-workspace/next-react-blog/node_modules/@prisma/client/runtime/library.js:128:9763)
at async getUserByAccount (webpack-internal:///(rsc)/./node_modules/@auth/prisma-adapter/index.js:220:29) {
name: 'GetUserByAccountError',
code: undefined
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant