holdenH
Convex Community3y ago
21 replies
holden

Validating id/schema values client side?

I have a NextJS route like app/project/[id], so my id comes in from a URL param.
I want to render a 404 page if the id isn't valid.

The docs suggest casting on the client, like this:
const project = useQuery(api.projects.get, { id: projectId as Id<"projects"> });


This correctly throws if the string isn't a valid id. Should I just catch this on the client to render a 404? Or is there some way to run a validator in a client component? I was imagining something like zod.safeParse where I could test if a string is a valid Id<"projects">.
Was this page helpful?