I might not be asking this correctly I'm still very new to this;
I'm attempting to create a const that checks to see whether the user is a valid member of the server being loaded.
within my layout.tsx in my main routes folder I have the following (extract not the full code)
const ServerIdLayout = async ({
children,
params,
}: {
children: React.ReactNode;
params: { serverId: string };
}) => {
const profile = await currentProfile();
if (!profile) {
return redirectToSignIn();
}
const server = await db.server.findUnique({
where: {
id: params.serverId,
members: {
some: {
profileId: profile.id
}
}
}
});
The error is stating that the where function requires an 'id' or 'id' argument and states that the id is undefined.
Error response:
Error:
Invalid `prisma.server.findUnique()` invocation:
{
where: {
id: undefined,
members: {
some: {
profileId: "b04f5e32-6b4b-411d-a63d-34b37c523ffd"
}
},
? AND?: ServerWhereInput | ServerWhereInput[],
? OR?: ServerWhereInput[],
? NOT?: ServerWhereInput | ServerWhereInput[],
? name?: StringFilter | String,
? imageUrl?: StringFilter | String,
? inviteCode?: StringFilter | String,
? profileId?: StringFilter | String,
? createdAt?: DateTimeFilter | DateTime,
? updatedAt?: DateTimeFilter | DateTime,
? profile?: ProfileRelationFilter | ProfileWhereInput,
? channels?: ChannelListRelationFilter
}
}
Argument where of type ServerWhereUniqueInput needs at least one of id or id arguments. Available options are marked with ?.
I'm not sure where I'm going wrong. The code works fine if I use findFirst(); but not findUnique();
for reference my schema.prisma looks like this:
model Server {
id String @id @unique @default(uuid()) @db.VarChar(255)
name String
imageUrl String @db.Text
inviteCode String @db.Text
profileId String
profile Profile @relation(fields: [profileId], references: [id], onDelete: Cascade)
members Member[]
channels Channel[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@index([profileId])
}
and in my .env my DATABASE_URL ends with sslaccept=strict
I have attempted multiple variants within my schema.prisma file and each time ran npx prisma generate && npx prisma db push in my terminal before re-loading my npm run dev
so after going through all my code it turns out my folder was named [serverid] not [serverId]
which was causing my params to not be able to read the URL hence the undefined value