wrux
wrux3w ago

Best solution for checks like unique username

Right now I am building an app with Vite React and zod, react-hook-form. I have a form that does not check uniqueness on the username, but if I add a check, what would be the "best practice"? My Convext backend checks if already exists, I'm just wondering where to add the check on the frontend.
6 Replies
Convex Bot
Convex Bot3w ago
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!
wrux
wruxOP3w ago
Would it be best to add the check directly into the Zod schema?
ballingt
ballingt3w ago
I'd check with a Convex query, one called api.users.usernameExists.
wrux
wruxOP3w ago
Yeah I have that exact endpoint, but would you place the query into a Zod validator, or into the form on submit function? I don't want to overload the API for no reason so I'm thinking in the on submit. Also, what's the recommended way to jsut fire a regular await fetch request with Convex?
ballingt
ballingt3w ago
Is this in React? convex.query() where convex is what you get from useConvex()
wrux
wruxOP3w ago
I ended up using convex.query yeah

Did you find this page helpful?