First Prisma thing with next-auth

Hi guys, I'm trying to get started with prisma, and i thought on eof the first thigns i should do was to add a logins count to the user's account .... Im just getting a simple "ERROR" no feedback Any idea what's wrong here? [..nextauth]
callbacks: {
async signIn({ user, account, profile, email, credentials }) {
const params = { user, account, profile, email, credentials };
return await onSignin(params);
},
},
callbacks: {
async signIn({ user, account, profile, email, credentials }) {
const params = { user, account, profile, email, credentials };
return await onSignin(params);
},
},
onSignIn
export default async function onSignin({
user,
account,
profile,
email,
credentials,
}: NextCallbackProps) {
console.log("onSignin", { user, account, profile, email, credentials });
return await prisma.account.update({
where: {
id: user.id,
},
data: {
lastLoginAt: new Date(),
logins: {
increment: 1,
},
},
});
}
export default async function onSignin({
user,
account,
profile,
email,
credentials,
}: NextCallbackProps) {
console.log("onSignin", { user, account, profile, email, credentials });
return await prisma.account.update({
where: {
id: user.id,
},
data: {
lastLoginAt: new Date(),
logins: {
increment: 1,
},
},
});
}
mysql prisma schema:
prisma
model Account {
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
logins Int @default(0)
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
lastLoginAt DateTime @default(now())
prisma
model Account {
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
logins Int @default(0)
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
lastLoginAt DateTime @default(now())
13 Replies
fotoflo
fotoflo•2y ago
And how do i get a good error code ?
Hycord | @ When Replying
Where is the error code being thrown? I'm certain theres a deeper error message either you haven't mentioned, or haven't found
Valhalaar
Valhalaar•2y ago
yeah I'm looking at this code and the first thing that jumps out is that there's no try-catch going on here i don't know if that's standard / idiomatic for this kind of setup, but it kinda strikes me as a little odd you don't have any error handling
fotoflo
fotoflo•2y ago
hahah ok first prisma @Valhalaar makes sense that's how i can find the error
Valhalaar
Valhalaar•2y ago
yeah wrap your return awaits in a try catch and see if there's an error being thrown that's my only real advice as a non-Prisma user
fotoflo
fotoflo•2y ago
name: 'OAuthCallbackError', code: undefined }, providerId: 'google', message: 'checks.state argument is missing got an error yay i should probably move this to the user from the account
Valhalaar
Valhalaar•2y ago
checks.state is missing so that's the problem not sure where that is but that should give you a hint as to where you can start looking to fix this
fotoflo
fotoflo•2y ago
i moved it to the user and it appears to work sort of
try {
const result = await prisma.user.update({
where: {
id: user.id,
},
data: {
lastLoginAt: new Date(),
logins: {
increment: 1,
},
},
});

debugger;
return result;
} catch (err) {
console.log("Prisma Error" + err);
}
}
try {
const result = await prisma.user.update({
where: {
id: user.id,
},
data: {
lastLoginAt: new Date(),
logins: {
increment: 1,
},
},
});

debugger;
return result;
} catch (err) {
console.log("Prisma Error" + err);
}
}
the debugger showed that logins was 3 but in my prisma studio... i dont see the logins must be setup to look at production haha im too noob prisma studio should tell you which env its own on thank you @Valhalaar the try-catch got me there 🙂
Valhalaar
Valhalaar•2y ago
sweet! here's a good article btw if it helps
Valhalaar
Valhalaar•2y ago
I had a hard time understanding some of this stuff until I read this article a few times
fotoflo
fotoflo•2y ago
thank you
Valhalaar
Valhalaar•2y ago
sure thing!
Want results from more Discord servers?
Add your server