Run the web app (operator)
The web app is the front end of the free tier: the public pages, sign-in, the study form, the
result page and the shared result. It is a Next.js app in web/. It holds no data of its own:
sign-in goes to Supabase, and everything else goes to the API
(Run the API).
What it does
| Page | Who | What |
|---|---|---|
/ |
anyone | What the product is, with an example result |
/sign-in |
anyone | Sign in or sign up with an email link |
/welcome |
signed in, first visit | The two optional questions and the marketing tick box |
/studies, /studies/new, /studies/{id} |
signed in | List, create, run, read, share and delete studies |
/account |
signed in | Profile, marketing consent, sign out |
/admin |
operators | Accounts, opt-ins, studies by state, today's free-tier spend |
/r/{slug} |
anyone with the link | A shared result, without individual answers |
/confirm?token= |
link from the email | Confirms marketing consent |
/accuracy |
anyone | What has and has not been measured about accuracy |
/help, /help/{article} |
anyone | These articles, read from docs/help/en/kb/ |
How it talks to the API: the browser only calls this app. Requests under /api/ are passed on to
the API at API_URL, with the visitor's sign-in token. The API is never exposed to the browser
directly, so it needs no cross-origin settings.
Getting started (operator, in this order)
Start the API first and check
GET /healthanswers{"ok": true}(Run the API).Set the web app's settings. Copy
web/.env.exampletoweb/.env.localand fill in:Name Meaning NEXT_PUBLIC_SUPABASE_URLThe project address, https://<project-ref>.supabase.coNEXT_PUBLIC_SUPABASE_KEYThe project's publishable key (starts sb_publishable_), from Supabase: Project Settings, API Keys. It is public by design. Never put the secret key (sb_secret_) hereNEXT_PUBLIC_SITE_URLThe public address of the site, https://koloriq.comin production. It is written into each page's canonical and sharing tags. Defaulthttp://localhost:3000. It must be the same address as the API'sPUBLIC_BASE_URL, which makes the links in emails and share linksAPI_URLWhere this app's server reaches the API. Default http://127.0.0.1:8000. Read when the app is builtHELP_DIROptional. The folder with the help articles, if it is not ../docs/help/en/kbTell Supabase where the app lives. In Supabase: Authentication, URL Configuration, set Site URL to the app's address (
http://localhost:3000on your own machine). The sign-in link sends people back to that address.Set
PUBLIC_BASE_URLon the API to the same address. Share links and email links are built from it.Install and start:
cd web npm installOn your own machine:
npm run devOn a server:
npm run build npm run startCheck it: open the app, sign in with your email, create a study and run it. With the API's
MARKETSIM_PROVIDERleft atfakethe result is marked "Dry run" and costs nothing.Make yourself an operator (step 5 of Run the API) to see
/admin.
Checks before a change is merged
cd web
npm run lint
npm run typecheck
npm test
npm run build
Settings and limits
- Sign-in is by email link only. Google sign-in is not switched on; it needs OAuth credentials in the Supabase project first.
- Sign-in email comes from Supabase's own sender, which allows only a few messages an hour. Set up your own mail sender in Supabase before the app is public.
API_URLand theNEXT_PUBLICvalues are fixed when the app is built. Change one, then build again.- The help articles are read when the app is built. A new or changed article appears after the next build.
- The description is typed. A pasted page address and a screenshot upload are not built, and the audience is edited by hand from three ready-made mixes; the audience builder is not built.
- Not deployed. There is no container or server setup for the web app yet.
Signing in with the emailed code
The sign-in email carries a 6-digit code and a button. The code can be typed into the sign-in page from any device, so it works when the email is read on a phone and the app is open on a computer, and when a company mail scanner has already opened the button's link. Setting up the email itself is in Email setup.
| Message | Cause | Fix |
|---|---|---|
| "Enter the 6-digit code from the email." | The code box is empty or does not hold six digits | Type the six digits from the newest email |
| "That code did not work. It may have expired or been used already. Check the newest email, or send a new code." | The code is older than an hour, was already used (also by the button), or belongs to an earlier email | Use the newest email, or choose send a new code |
Troubleshooting
| Message or symptom | Cause | Fix |
|---|---|---|
| "Sign-in is not set up on this copy of the app: NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_KEY are missing." | One of the two settings is empty | Fill both in web/.env.local, then restart (or rebuild on a server) |
| "The sign-in email could not be sent. Please try again in a moment." | Supabase refused the request: a wrong key, or email sign-in is switched off in the project | Check the publishable key and that the Email provider is enabled in Supabase |
| The sign-in link opens the wrong address, or the app shows you signed out after clicking it | Site URL in Supabase does not match the address the app runs on | Set Site URL to the app's address (step 3) |
| "The service could not be reached. Check your connection and try again." | The browser could not reach this app | Check the app is running |
| "Something went wrong on our side. Please try again in a moment." on every page | The app cannot reach the API at API_URL, or the API is down |
Start the API; check API_URL; rebuild if it changed |
| "Your sign-in has expired or is not valid. Sign in again." for everyone | The API checks tokens against a different Supabase project than the app signs in to | Make the API's SUPABASE_JWKS_URL (or secret) and the app's NEXT_PUBLIC_SUPABASE_URL point at the same project |
| "The help articles are not available in this copy of the app." | The articles folder was not found when the app was built | Build from the repository, or set HELP_DIR |
Shared links point at localhost |
PUBLIC_BASE_URL on the API is not the public address |
Set it and restart the API |
"Operators only." on /admin |
The account is not an operator | Step 7 above |