[BUG] @@auth doesn't work if a User model is defined
Description and expected behavior
If you specify @@auth on a model but also have a User model defined, Zenstack uses the User model for the AuthUser type.
model AuthUser {
@@auth
id String @id
}
model User {
id String @id @default(cuid())
}
With the models above, enhance expects a type matching User despite me marking AuthUser as @@auth.
Currently my workaround is to not use @@auth, and name my AuthUser model User, but that's forced me to name my "real" User model to something else, which I don't want to do.
model User {
id String @id
}
model RealUser {
id String @id @default(cuid())
}
Expected behaviour
I can use @@auth on a Model and still define a User model myself.
Environment (please complete the following information)
- ZenStack version: 2.5.1
- Prisma version: 5.18.0
- Database type: Postgresql
I've also just noticed that with this set up:
model User {
@@ignore
id String @id
}
model RealUser {
id String @id @default(cuid())
}
The type of user in enhance call is simply Record<string, unknown>. It would be nice if Zenstack could still generate the correct type based on the Model fields.
OK going to edit the bug. It looks like @@ignore is a red herring. @@auth simply doesn't work if you have a model called User.
model AuthUser { @@auth id String @id }
model User { id String @id @default(cuid()) }
Hi @onimitch , thanks for filing this. I tried with the latest release but couldn't reproduce the issue with this model:
model AuthUser {
@@auth
id String @id
}
model User {
id String @id @default(cuid())
}
The typing of the generated enhance function looks correct. Do you have a project that can expose this? Thanks!
Btw, v2.9 will allow to use a "type" as "@@auth" so you don't need to use the "@@ignore" hack anymore.
Closing for now. Please feel free to reactivate if it's still an issue.