P
Prisma5mo ago
infinity

Getting P2023 When getting params

I am getting this error message when getting params with the id:
code: 'P2023',
clientVersion: '5.17.0',
meta: {
modelName: 'User',
message: 'Malformed ObjectID: provided hex string representation must be exactly 12 bytes, instead got: "undefined", length 9.'
}
}
GET /api/users/undefined 500 in 649ms
{
message: 'Failed to fetch user',
error: {
name: 'PrismaClientKnownRequestError',
code: 'P2023',
clientVersion: '5.17.0',
meta: {
modelName: 'User',
message: 'Malformed ObjectID: provided hex string representation must be exactly 12 bytes, instead got: "undefined", length 9.'
}
}
}
code: 'P2023',
clientVersion: '5.17.0',
meta: {
modelName: 'User',
message: 'Malformed ObjectID: provided hex string representation must be exactly 12 bytes, instead got: "undefined", length 9.'
}
}
GET /api/users/undefined 500 in 649ms
{
message: 'Failed to fetch user',
error: {
name: 'PrismaClientKnownRequestError',
code: 'P2023',
clientVersion: '5.17.0',
meta: {
modelName: 'User',
message: 'Malformed ObjectID: provided hex string representation must be exactly 12 bytes, instead got: "undefined", length 9.'
}
}
}
1 Reply
infinity
infinityOP5mo ago
This is my schema:
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}

model Products {
id String @id @default(auto()) @map("_id") @db.ObjectId
pid Int @unique
slug String @unique
productName String
brand String
imageUrl String[]
itemWeight Float
price Float
quantity Int
content String?
category String
apiCountry String?

user User @relation(fields: [userId], references: [id])
userId String @db.ObjectId

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}

model VendorProfile {
id String @id @default(auto()) @map("_id") @db.ObjectId
firstName String
lastName String
email String
phoneNumber Int
apiCountry String?
userCountry String?

user User @relation(fields: [userId], references: [id])
userId String @db.ObjectId @unique

createdAt DateTime @default(now())
updatedAt DateTime? @updatedAt
}

enum UserRole {
ADMIN
CUSTOMER
VENDOR
STAFF
}

model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
firstName String
lastName String
email String @unique
emailVerified DateTime?
password String
phoneNumber Int
apiCountry String?
userCountry String

products Products[]
role UserRole @default(CUSTOMER)
vendorProfile VendorProfile?

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}

model Products {
id String @id @default(auto()) @map("_id") @db.ObjectId
pid Int @unique
slug String @unique
productName String
brand String
imageUrl String[]
itemWeight Float
price Float
quantity Int
content String?
category String
apiCountry String?

user User @relation(fields: [userId], references: [id])
userId String @db.ObjectId

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}

model VendorProfile {
id String @id @default(auto()) @map("_id") @db.ObjectId
firstName String
lastName String
email String
phoneNumber Int
apiCountry String?
userCountry String?

user User @relation(fields: [userId], references: [id])
userId String @db.ObjectId @unique

createdAt DateTime @default(now())
updatedAt DateTime? @updatedAt
}

enum UserRole {
ADMIN
CUSTOMER
VENDOR
STAFF
}

model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
firstName String
lastName String
email String @unique
emailVerified DateTime?
password String
phoneNumber Int
apiCountry String?
userCountry String

products Products[]
role UserRole @default(CUSTOMER)
vendorProfile VendorProfile?

createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
This is where I want to render the data that I extract:
import React from 'react';
import Vendor from '@/components/frontend/onboardProfile/vendor';
import { getData } from '@/app/lib/getData';

export default async function Page({ params: { id } }) {
const user = await getData(`users/${id}`);
console.log(user);

return (
<div className='flex flex-col justify-center items-center'>
<h2>Hello {user.firstName}, welcome to our page</h2>
<Vendor user={user} />
</div>
);
}
import React from 'react';
import Vendor from '@/components/frontend/onboardProfile/vendor';
import { getData } from '@/app/lib/getData';

export default async function Page({ params: { id } }) {
const user = await getData(`users/${id}`);
console.log(user);

return (
<div className='flex flex-col justify-center items-center'>
<h2>Hello {user.firstName}, welcome to our page</h2>
<Vendor user={user} />
</div>
);
}
Want results from more Discord servers?
Add your server