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)

  1. Start the API first and check GET /health answers {"ok": true} (Run the API).

  2. Set the web app's settings. Copy web/.env.example to web/.env.local and fill in:

    Name Meaning
    NEXT_PUBLIC_SUPABASE_URL The project address, https://<project-ref>.supabase.co
    NEXT_PUBLIC_SUPABASE_KEY The 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_) here
    NEXT_PUBLIC_SITE_URL The public address of the site, https://koloriq.com in production. It is written into each page's canonical and sharing tags. Default http://localhost:3000. It must be the same address as the API's PUBLIC_BASE_URL, which makes the links in emails and share links
    API_URL Where this app's server reaches the API. Default http://127.0.0.1:8000. Read when the app is built
    HELP_DIR Optional. The folder with the help articles, if it is not ../docs/help/en/kb
  3. Tell Supabase where the app lives. In Supabase: Authentication, URL Configuration, set Site URL to the app's address (http://localhost:3000 on your own machine). The sign-in link sends people back to that address.

  4. Set PUBLIC_BASE_URL on the API to the same address. Share links and email links are built from it.

  5. Install and start:

    cd web
    npm install
    

    On your own machine:

    npm run dev
    

    On a server:

    npm run build
    npm run start
    
  6. Check it: open the app, sign in with your email, create a study and run it. With the API's MARKETSIM_PROVIDER left at fake the result is marked "Dry run" and costs nothing.

  7. 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_URL and the NEXT_PUBLIC values 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