nextauthjs / nextauthjs/next-auth
MySQL Prisma schema has an inconsistent Account relation
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 28.4k
- Forks
- 4k
- PR merge metrics
- No merged PRs in 30d
Description
The MySQL schema in the Prisma adapter documentation defines an inconsistent relationship between User and Account:
model User {
accounts Account[]
}
model Account {
userId String @unique
user User? @relation(fields: [userId], references: [id])
}
There are two issues:
userIdis required, but the correspondinguserrelation is marked as optional.userId @uniqueprevents multiple accounts from referencing the same user. This conflicts withaccounts Account[]and prevents users from linking
multiple providers.
The relationship should instead be:
model User {
accounts Account[]
}
model Account {
userId String
user User @relation(fields: [userId], references: [id])
}
The existing @@unique([provider, providerAccountId]) constraint should remain because it uniquely identifies each provider account.
Is there any context that might help us understand?
The PostgreSQL, SQLite, and MongoDB examples use a required, non-unique userId and a required User relation.
Aligning the MySQL example with them accurately models the intended one-to-many relationship: every account belongs to one user, while one user may link
multiple provider accounts, such as GitHub and Google.
Does the docs page already exist? Please link to it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open the Prisma adapter documentation at the linked authjs.dev page and locate the MySQL schema example. Compare it with the PostgreSQL, SQLite, and MongoDB examples, then update the Account relation to match the stated one-to-many relationship while keeping @@unique([provider, providerAccountId]). Done when the MySQL example permits multiple accounts per user and uses a required user relation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql
- Domain
- databases, documentation
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100