我在使用Google适配器进行Next Authentication时遇到此错误。
✓ Compiled /api/auth/[...nextauth] in 371ms (70 modules)
(node:9269) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
[next-auth][error][adapter_error_getUserByAccount]
https://next-auth.js.org/errors#adapter_error_getuserbyaccount
Invalid `p.account.findUnique()` invocation in
/Users/ASUS/outsidetest4/node_modules/@next-auth/prisma-adapter/dist/index.js:211:45
208 getUserByEmail: (email) => p.user.findUnique({ where: { email } }),
209 async getUserByAccount(provider_providerAccountId) {
210 var _a;
→ 211 const account = await p.account.findUnique({
where: {
provider_providerAccountId: {
~~~~~~~~~~~~~~~~~~~~~~~~~~
providerAccountId: "104357183920961836781",
provider: "google"
},
? id?: Int,
? AND?: AccountWhereInput | AccountWhereInput[],
? OR?: AccountWhereInput[],
? NOT?: AccountWhereInput | AccountWhereInput[],
? userId?: IntNullableFilter | Int | Null,
? provider?: 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?: UserNullableRelationFilter | UserWhereInput | Null
},
select: {
user: true
}
})
Unknown argument `provider_providerAccountId`. Available options are marked with ?. {
message: '\n' +
'Invalid `p.account.findUnique()` invocation in\n' +
'/Users/ASUS/outsidetest4/node_modules/@next-auth/prisma-adapter/dist/index.js:211:45\n' +
'\n' +
' 208 getUserByEmail: (email) => p.user.findUnique({ where: { email } }),\n' +
' 209 async getUserByAccount(provider_providerAccountId) {\n' +
' 210 var _a;\n' +
'→ 211 const account = await p.account.findUnique({\n' +
' where: {\n' +
' provider_providerAccountId: {\n' +
' ~~~~~~~~~~~~~~~~~~~~~~~~~~\n' +
' providerAccountId: "104357183920961836781",\n' +
' provider: "google"\n' +
' },\n' +
' ? id?: Int,\n' +
' ? AND?: AccountWhereInput | AccountWhereInput[],\n' +
' ? OR?: AccountWhereInput[],\n' +
' ? NOT?: AccountWhereInput | AccountWhereInput[],\n' +
' ? userId?: IntNullableFilter | Int | Null,\n' +
' ? provider?: 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?: UserNullableRelationFilter | UserWhereInput | Null\n' +
' },\n' +
' select: {\n' +
' user: true\n' +
' }\n' +
' })\n' +
'\n' +
'Unknown argument `provider_providerAccountId`. Available options are marked with ?.',
stack: 'PrismaClientValidationError: \n' +
'Invalid `p.account.findUnique()` invocation in\n' +
'/Users/ASUS/outsidetest4/node_modules/@next-auth/prisma-adapter/dist/index.js:211:45\n' +
'\n' +
' 208 getUserByEmail: (email) => p.user.findUnique({ where: { email } }),\n' +
' 209 async getUserByAccount(provider_providerAccountId) {\n' +
' 210 var _a;\n' +
'→ 211 const account = await p.account.findUnique({\n' +
' where: {\n' +
' provider_providerAccountId: {\n' +
' ~~~~~~~~~~~~~~~~~~~~~~~~~~\n' +
' providerAccountId: "104357183920961836781",\n' +
' provider: "google"\n' +
' },\n' +
' ? id?: Int,\n' +
' ? AND?: AccountWhereInput | AccountWhereInput[],\n' +
' ? OR?: AccountWhereInput[],\n' +
' ? NOT?: AccountWhereInput | AccountWhereInput[],\n' +
' ? userId?: IntNullableFilter | Int | Null,\n' +
' ? provider?: 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?: UserNullableRelationFilter | UserWhereInput | Null\n' +
' },\n' +
' select: {\n' +
' user: true\n' +
' }\n' +
' })\n' +
'\n' +
'Unknown argument `provider_providerAccountId`. Available options are marked with ?.\n' +
' at ti (/Users/ASUS/outsidetest4/node_modules/@prisma/client/runtime/library.js:118:5888)\n' +
' at si.handleRequestError (/Users/ASUS/outsidetest4/node_modules/@prisma/client/runtime/library.js:125:6473)\n' +
' at si.handleAndLogRequestError (/Users/ASUS/outsidetest4/node_modules/@prisma/client/runtime/library.js:125:6151)\n' +
' at si.request (/Users/ASUS/outsidetest4/node_modules/@prisma/client/runtime/library.js:125:5859)\n' +
' at async l (/Users/ASUS/outsidetest4/node_modules/@prisma/client/runtime/library.js:130:10025)\n' +
' at async getUserByAccount (/Users/ASUS/outsidetest4/node_modules/@next-auth/prisma-adapter/dist/index.js:211:29)',
name: 'PrismaClientValidationError'
}
[next-auth][error][OAUTH_CALLBACK_HANDLER_ERROR]
https://next-auth.js.org/errors#oauth_callback_handler_error
Invalid `p.account.findUnique()` invocation in
/Users/ASUS/outsidetest4/node_modules/@next-auth/prisma-adapter/dist/index.js:211:45
208 getUserByEmail: (email) => p.user.findUnique({ where: { email } }),
209 async getUserByAccount(provider_providerAccountId) {
210 var _a;
→ 211 const account = await p.account.findUnique({
where: {
provider_providerAccountId: {
~~~~~~~~~~~~~~~~~~~~~~~~~~
providerAccountId: "104357183920961836781",
provider: "google"
},
? id?: Int,
? AND?: AccountWhereInput | AccountWhereInput[],
? OR?: AccountWhereInput[],
? NOT?: AccountWhereInput | AccountWhereInput[],
? userId?: IntNullableFilter | Int | Null,
? provider?: 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?: UserNullableRelationFilter | UserWhereInput | Null
},
select: {
user: true
}
})
Unknown argument `provider_providerAccountId`. Available options are marked with ?. PrismaClientValidationError:
Invalid `p.account.findUnique()` invocation in
/Users/ASUS/outsidetest4/node_modules/@next-auth/prisma-adapter/dist/index.js:211:45
208 getUserByEmail: (email) => p.user.findUnique({ where: { email } }),
209 async getUserByAccount(provider_providerAccountId) {
210 var _a;
→ 211 const account = await p.account.findUnique({
where: {
provider_providerAccountId: {
~~~~~~~~~~~~~~~~~~~~~~~~~~
providerAccountId: "104357183920961836781",
provider: "google"
},
? id?: Int,
? AND?: AccountWhereInput | AccountWhereInput[],
? OR?: AccountWhereInput[],
? NOT?: AccountWhereInput | AccountWhereInput[],
? userId?: IntNullableFilter | Int | Null,
? provider?: 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?: UserNullableRelationFilter | UserWhereInput | Null
},
select: {
user: true
}
})
Unknown argument `provider_providerAccountId`. Available options are marked with ?.
at ti (/Users/ASUS/outsidetest4/node_modules/@prisma/client/runtime/library.js:118:5888)
at si.handleRequestError (/Users/ASUS/outsidetest4/node_modules/@prisma/client/runtime/library.js:125:6473)
at si.handleAndLogRequestError (/Users/ASUS/outsidetest4/node_modules/@prisma/client/runtime/library.js:125:6151)
at si.request (/Users/ASUS/outsidetest4/node_modules/@prisma/client/runtime/library.js:125:5859)
at async l (/Users/ASUS/outsidetest4/node_modules/@prisma/client/runtime/library.js:130:10025)
at async getUserByAccount (/Users/ASUS/outsidetest4/node_modules/@next-auth/prisma-adapter/dist/index.js:211:29) {
name: 'GetUserByAccountError',
code: undefined
}
字符串
我的schema看起来是这样的:
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model User {
id Int @id @unique @default(autoincrement())
firstName String
lastName String
email String @unique
username String @unique
password String
image String?
role UserRole @default(NORMAL)
emailVerified DateTime?
sessions Session[] @relation("Session_user")
accounts Account[] @relation("Account_user")
verificationTokens VerificationToken[] // If you want to associate multiple verification tokens with a user
listings Listing[] @relation("Listing_user")
bookings Booking[] @relation("Booking_user")
likes Like[] @relation("Like_user")
searches Search[] @relation("Search_user")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
enum UserRole {
NORMAL
ALPHA
}
model Category {
id Int @id @unique @default(autoincrement())
name String
listings Listing[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Listing {
id Int @id @unique @default(autoincrement())
name String
host User @relation("Listing_user", fields: [hostId], references: [id])
hostId Int
images String[]
shortCaption String
description String
price Decimal
startDate DateTime
endDate DateTime
location String
coordinates Coordinates? @relation(fields: [coordinatesId], references: [id])
likes Like[] @relation("Like_listing")
bookings Booking[] @relation("Booking_listing")
coordinatesId Int?
categories Category[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Approved Boolean
}
model Like {
id Int @id @unique @default(autoincrement())
user User @relation("Like_user", fields: [userId], references: [id])
userId Int
listing Listing @relation("Like_listing", fields: [listingId], references: [id])
listingId Int
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Booking {
id Int @id @unique @default(autoincrement())
user User @relation("Booking_user", fields: [userId], references: [id])
userId Int
listing Listing @relation("Booking_listing", fields: [listingId], references: [id])
listingId Int
request String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Search {
id Int @id @unique @default(autoincrement())
keyword String
timestamp DateTime @default(now())
user User? @relation("Search_user", fields: [userId], references: [id])
userId Int?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Coordinates {
id Int @id @unique @default(autoincrement())
name String
latitude Float
longitude Float
listingId Int
listings Listing[] @relation
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Session {
id Int @id @unique @default(autoincrement())
sessionToken String @unique
userId Int?
expires DateTime
user User? @relation("Session_user", fields: [userId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model Account {
id Int @id @unique @default(autoincrement())
userId Int?
provider String
providerId String
providerAccountId String
refreshToken String?
accessToken String?
accessTokenExpires DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User? @relation("Account_user", fields: [userId], references: [id], onDelete: Cascade)
}
model VerificationToken {
id Int @id @unique @default(autoincrement())
identifier String
token String @unique
expires DateTime
userId Int // Assuming each verification token is associated with a user
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([identifier, token])
}
型
我已经在互联网上寻找修复方法,但似乎没有任何工作
我已经尝试更新我的模型,仍然没有任何东西。我正在使用Next.js和Prisma与我的数据库和前端通信。
我的配置文件看起来像这样:
// import { PrismaAdapter } from '@next-auth/prisma-adapter';
// import { PrismaClient } from '@prisma/client';
// import NextAuth from "next-auth";
// import EmailProvider from "next-auth/providers/email";
// import GoogleProvider from "next-auth/providers/google";
// const prisma = new PrismaClient();
// export default NextAuth({
// adapter: PrismaAdapter(prisma),
// providers: [
// GoogleProvider({
// clientId: process.env.GOOGLE_CLIENT_ID,
// clientSecret: process.env.GOOGLE_CLIENT_SECRET,
// authorization: {
// params: {
// prompt: "consent",
// access_type: "offline",
// response_type: "code"
// }
// },
// profile(profile) {
// return {
// id: profile.sub,
// name: profile.name || profile.login,
// email: profile.email,
// image: profile.avatar_url,
// };
// },
// }),
// EmailProvider({
// server: {
// host: process.env.EMAIL_SERVER_HOST,
// port: process.env.EMAIL_SERVER_PORT,
// auth: {
// user: process.env.EMAIL_SERVER_USER,
// pass: process.env.EMAIL_SERVER_PASSWORD,
// },
// },
// from: process.env.EMAIL_FROM,
// maxAge: 10 * 60 * 60,
// profile(profile) {
// return {
// name: profile.name || profile.login,
// email: profile.email,
// image: profile.avatar_url,
// };
// },
// }),
// ],
// callbacks: {
// async signIn({ account, profile, isNewUser }) {
// if (account.provider === 'google') {
// const existingAccount = await prisma.account.findUnique({
// where: {
// providerAccountId: profile.sub, // Change this to the correct field name
// providerType: 'google',
// },
// select: {
// user: true,
// },
// });
// // If the account exists, you might want to update it or perform additional checks
// if (existingAccount) {
// // Do something with the existing account
// }
// // If it's a new user, create an entry in your database
// if (isNewUser) {
// await prisma.user.create({
// data: {
// id: profile.sub, // Change this to the correct field name
// email: profile.email,
// firstName: profile.given_name || '',
// lastName: profile.family_name || '',
// username: profile.given_name + "_username", // Change this to the appropriate field from the profile
// password: 'a_default_password', // Change this to the appropriate field from the profile
// image: profile.picture,
// // Add other fields as needed
// },
// });
// }
// // Return true if the user should be allowed to sign in
// return true;
// }
// return true; // Do different verification for other providers that don't have `email_verified`
// },
// },
// });
import NextAuth from 'next-auth'
import { PrismaClient } from '@prisma/client'
import { PrismaAdapter } from '@next-auth/prisma-adapter';
import EmailProvider from "next-auth/providers/email";
import GoogleProvider from "next-auth/providers/google";
const prisma = new PrismaClient()
export default NextAuth({
adapter: PrismaAdapter(prisma),
providers: [
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
authorization: {
params: {
prompt: "consent",
access_type: "offline",
response_type: "code"
}
},
profile(profile) {
return {
id: profile.sub,
name: profile.name || profile.login,
email: profile.email,
image: profile.avatar_url,
};
},
}),
EmailProvider({
server: {
host: process.env.EMAIL_SERVER_HOST,
port: process.env.EMAIL_SERVER_PORT,
auth: {
user: process.env.EMAIL_SERVER_USER,
pass: process.env.EMAIL_SERVER_PASSWORD,
},
},
from: process.env.EMAIL_FROM,
maxAge: 10 * 60 * 60,
profile(profile) {
return {
name: profile.name || profile.login,
email: profile.email,
image: profile.avatar_url,
};
},
}),
],
callbacks: {
async session(session, user) {
session.userId = user.id;
return session;
},
async jwt(token, user, account, profile, isNewUser) {
if (user) {
token.id = user.id;
}
return token;
},
},
})
型
1条答案
按热度按时间uplii1fm1#
如果你没有迁移
字符串
如果问题仍然存在
型