- this is my api routes file
in this api routes i get the id from session in auth.ts file
export async function GET(request: Request) {
const session = await auth()
const bookings = await prisma.booking.findMany({
where: {
user_id: {
equals: session?.user.id
}
},
include: {
user_book: {
select: {
name: true,
email: true,
image: true,
nomor_hp: true,
},
},
mobil_book: {
select: {
merk: true,
type: true,
nomor_plat: true,
persneling: true,
bahan_bakar: true,
image: true,
tarif: true,
},
},
},
});
return NextResponse.json({ bookings: bookings }, { status: 200 });
}
- this is my function file to get the data and return json
export async function getBooking() {
const res = await fetch("http://localhost:3000/api/booking")
// The return value is *not* serialized
// You can return Date, Map, Set, etc.
if (!res.ok) {
// This will activate the closest `error.js` Error Boundary
return new Error('Failed to fetch data')
}
return res.json()
};
i want to display data where current user can get their data, but im confuse, in api routes the data is empty, an then in component the data is still displaay, any guess anyone?
- this is my component ss
- this is my api routes ss