P
Prisma5mo ago
shardex

property 'data' does not exist on args when using $extends

Basically I was trying the method provided in the solution of this stack overflow post https://stackoverflow.com/questions/77435838/hash-password-in-prisma-orm whoever when building the index.ts file I get the following:
src/index.ts:12:62 - error TS2339: Property 'data' does not exist on type 'UserFindUniqueArgs<InternalArgs & DefaultArgs> | UserFindUniqueOrThrowArgs<InternalArgs & DefaultArgs> | ... 13 more ... | UserCountArgs<...>'.
Property 'data' does not exist on type 'UserFindUniqueArgs<InternalArgs & DefaultArgs>'.

12 if (["create", "update"].includes(operation) && args.data["password"]) {
src/index.ts:12:62 - error TS2339: Property 'data' does not exist on type 'UserFindUniqueArgs<InternalArgs & DefaultArgs> | UserFindUniqueOrThrowArgs<InternalArgs & DefaultArgs> | ... 13 more ... | UserCountArgs<...>'.
Property 'data' does not exist on type 'UserFindUniqueArgs<InternalArgs & DefaultArgs>'.

12 if (["create", "update"].includes(operation) && args.data["password"]) {
any idea?
Stack Overflow
Hash password in Prisma ORM
How to properly and elegantly hash a password in Prisma ORM when creating a model object? My prisma/schema.prisma file: generator client { provider = "prisma-client-js" } datasource db...
2 Replies
jonfanz
jonfanz5mo ago
Could you post your code snippet? That would help.
shardex
shardexOP5mo ago
I actually removed it and done it some other way, but it is a copy paste of the solution in the stackoverflow code:
const prisma = new PrismaClient().$extends({
query: {
user: {
$allOperations({ operation, args, query }) {
if (['create', 'update'].includes(operation) && args.data['password']) {
args.data['password'] = bcrypt.hashSync(args.data['password'], 10)
}
return query(args)
}
}
}
})
const prisma = new PrismaClient().$extends({
query: {
user: {
$allOperations({ operation, args, query }) {
if (['create', 'update'].includes(operation) && args.data['password']) {
args.data['password'] = bcrypt.hashSync(args.data['password'], 10)
}
return query(args)
}
}
}
})
here's my model if it helps
model User {
id String @id @default(uuid())
username String @unique
email String @unique
password String
}
model User {
id String @id @default(uuid())
username String @unique
email String @unique
password String
}
Want results from more Discord servers?
Add your server