How do I solve for a persisting session on Next-auth when User is deleted from DB.

I am currently finding that My user auth sessions are persisted even when I have cleared my db. What is the cleanest way around this. If possible kindly share a solution when using the jwt strategy as well
9 Replies
barry
barry3y ago
cascading show your model for the sessions
Mike Farad
Mike FaradOP3y ago
model Session {
id String @id @default(cuid())
sessionToken String @unique
userId String
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)

@@index([userId])
}
model Session {
id String @id @default(cuid())
sessionToken String @unique
userId String
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)

@@index([userId])
}
barry
barry3y ago
wait what oh you're using jwt's yeah just dont use jwt's this is simply a flaw with jwt's
Mike Farad
Mike FaradOP3y ago
okay, and there's no way to go around it when using jwts ?
barry
barry3y ago
☠️ just dont use jwts
Mike Farad
Mike FaradOP3y ago
okay, noted. Kind sir 😅
Neto
Neto3y ago
but if you do use jwt dont use long living ones like 1~2 minutes of ttl and keep refreshing
Mike Farad
Mike FaradOP3y ago
is it, possible to make the nextjs middleware feature work with the database strategy on nextauth?

Did you find this page helpful?