Validate dynamic route ID
When creating dynamic routes in Nextjs, how do we validate that the slug is a valid ID?
This is what I have so far:
3 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
only convex itself can validate an
_id. you're doing it correctly in the args validator.
an alternative, if you don't want to automatically throw an args validation error, is to accept the id as a string, then validate with ctx.db.normalizeId - then do what you wish with the result.I used normalizeId, thank you!
For anyone coming by this in the future, this is how I did it: