I follow the tutorial and do some tweet on my application, however for sign up it give me something like this
Invalid
this.dbAccessor.findUnique()
invocation in
V:\Self_Learning\redwoodjs\trml\node_modules@redwoodjs\auth-dbauth-api\dist\DbAuthHandler.js:852:42849 …userAttributes
850 } = this.params;
851 if (this._validateField(‘username’, username) && this._validateField(‘password’, password)) {
→ 852 const user = await this.dbAccessor.findUnique({
where: {
email: ‘abc@gmail.com’} }) Unknown arg `email` in where.email for type UserWhereUniqueInput. Did you mean `id`? Available args: type UserWhereUniqueInput { id?: BigInt }
The database I use is MySQL with snake form in the table, therefore in my schema.prisma
file I will have following:
model Role {
id BigInt @id @default(autoincrement()) @db.UnsignedBigInt
name String? @db.VarChar(255)
createdAt DateTime? @default(now()) @map("create_time") @db.Timestamp(0)
updatedAt DateTime? @updatedAt @map("update_time") @db.Timestamp(0)
app_user User[]
@@map("app_role")
}
model User {
id BigInt @id @default(autoincrement()) @db.UnsignedBigInt
lastName String @map("last_name") @db.VarChar(255)
firstName String @map("first_name") @db.VarChar(255)
username String @db.VarChar(255)
email String @unique @db.VarChar(255)
hashedPassword String @map("password") @db.VarChar(255)
salt String
createdAt DateTime? @default(now()) @map("create_time") @db.Timestamp(0)
updatedAt DateTime? @updatedAt @map("update_time") @db.Timestamp(0)
role_id BigInt? @db.UnsignedBigInt
app_role Role? @relation(fields: [role_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "app_user_app_role_id_fk")
Player Player[]
@@index([role_id], map: "app_user_app_role_id_fk")
@@map("app_user")
}
And after I run the yarn rw g dbAuth
, it created all the files for me successfully, and in the sign up page I added last name and first name into the page, but when I click on SINGUP
, it give me the error that I just mentioned above… try to search but I can’t find the solution on that…
EDIT: After I run the yarn rw prisma genarated
it didn’t give me that first error which I mentioned above, however I am facing second issue…
Invalid `db.user.create()` invocation in
V:\Self_Learning\redwoodjs\trml\api\src\functions\auth.js:108:22
105 // eslint-disable-next-line camelcase
106 handler: ({ lastName, firstName, username, hashedPassword }) => {
107 console.log(lastName, firstName, username, hashedPassword)
→ 108 return db.user.create({
data: {
+ lastName: String,
+ firstName: String,
email: 'abc@gmail.com',
username: 'abc@gmail.com',
hashedPassword: 'f3e682fa712f0a95eda14448da3c06fa5aad4d23423f32bc5ef907c7d222db20',
...
})
In my signup page I have last name, first name defined but it looks like not carry over to create the user…
EDIT2: Finally found why… in order to pass that lastName
and firstName
field I need to use userAttributes
, but not running into 3rd problem… it save successfully… however I got Do not know how to serialize a BigInt
and most of the solutions said… need to serialize
and deserialize
it by using following code :
JSON.stringify(
this,
(key, value) => (typeof value === 'bigint' ? value.toString() : value) // return everything else unchanged
)
but I don’t know where I should put it…