TrustVox
A feedback platform where reviewers earn TVX reward points for accepted feedback. Three roles, each walled off by Postgres row-level security.
- Next.js 15
- React 19
- TypeScript
- Supabase
- PostgreSQL
- Zod
- Tailwind CSS
- Grok API
Summary
Companies post feedback forms, an admin approves them, and users answer them. Accepted feedback earns TVX reward points, which users spend on coupons. TVX is an in-app points ledger, not crypto.
The problem
Feedback platforms get low-effort or fake responses because people have no reason to try. TrustVox pays for feedback that gets accepted. That meant building a points system nobody can cheat.
Setup
Three roles, each with its own dashboard: users (answer forms, TVX wallet, coupon store), clients (create forms and campaigns, see the responses) and admins (approve or reject forms, manage companies and users, block accounts, watch platform activity).
browser (public anon key only)
│
▼
Next.js server actions
zod validation · service-role key stays here
│
▼
Supabase Postgres
row-level security on every table
reward + spend: trusted database functions
Realtime ──▶ live notifications
- Data isolation: every table has row-level security policies, so each user only reads and changes their own rows. Postgres decides access from the session’s role, not application code.
- Points: TVX is paid and spent only through trusted server-side database functions, so nobody can give themselves points.
- Keys and input: the browser holds only the public anon key. Inputs are validated on the server with Zod.
- Logins: repeated failed logins trigger a lockout.
- AI (Grok API): critiques question quality while a client writes a form, generates questions, and summarises responses.
The demo: breaking my own reward system
During a full security review I found a way to mint points. One account could sign up as a company, create a form worth 2,000,000,000 TVX, answer its own form, and claim the reward: about 2 billion points to spend in the store. Each step was allowed on its own.
I closed it with three separate safeguards (migration 0008):
- rewards are capped at 1,000 TVX per form
- users can only answer forms an admin has approved
- nobody earns points from their own form
Then I tested it against the real database. All 9 checks passed:
reward 2,000,000,000 rejected
reward 1,000 allowed
reward 1,001 rejected
self-reward blocked, balance stays 0
normal reward +40 paid
same claim twice paid once
spend more than balance refused
What broke and how I fixed it
- Points were never actually paid out. The reward function failed with Postgres error
42P10: itsON CONFLICTclause didn’t match the unique index it was meant to use. No real user had ever received TVX, and nobody noticed because the browser test had been put off. Fixed with a one-line change in migration0006. - Anyone could sign up as admin. The signup trigger copied the role from data the browser sends, so someone could register as
admin. Now every signup starts as a plainuser, and only the trusted server can raise the role (migration0004). - Duplicate notifications. Two parts of the page asked for new notifications at the same moment and both inserted the same rows. Simultaneous requests are now merged into one.
- Login trap. A user still logged in who opened the company login page got sent straight back to their user dashboard. Opening a login page now signs out the old session first.
Lessons
- Test in the real browser right after building each part. The payout bug lived for a whole phase because I skipped this.
- Look at how features work together, not one at a time. The 2-billion-point bug needed three small gaps in different parts at once. Each part looked fine alone.
- Never fake numbers, even placeholders. The first version showed made-up stats (“Top 12%”, “1,240 TVX”) to every user. I replaced them with real data or removed them.