I'm just starting out with TypeScript.
Encountering the error 'No value exists in scope for the shorthand property 'firstName'. Either declare one or provide an initializer.' while using Prisma with Next.js to create a new user in my database.
The user model in schema.prisma
:
model User {
id Int @id @default(autoincrement())
email String @unique
firstName String
middleName String?
lastName String
dateOfBirth DateTime
mobileNumber String @unique
idType String
idNumber String @unique
idExpirtyDate DateTime
idIssueState DateTime
streetAddress String
suburb String
postCode Int
state String
bsb Int @unique
accountNumber Int @unique
payIdType String
payId String @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
The createUser()
function looks like this:
export async function createUser(user: FormData) {
const prisma = new PrismaClient()
await prisma.user.create({
data: {
firstName,
lastName,
middleName,
email,
dateOfBirth,
mobileNumber,
idType,
idNumber,
idExpirtyDate,
idIssueState,
streetAdddress,
suburb,
postCode,
state,
bsb,
accountNumber,
payIdType,
payId,
},
})
}
This is where I'm getting the FormData, from a component:
async function handleFormData(userData: FormData) {
'use server'
await createUser(userData)
}
Any assistance would be greatly appreciated.