Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.
export const meta = { title: 'Supabase', description: 'Supabase handles sign-in and stores every account, scheduled post and tracked item.' }
<Steps>
<Step title="Create a project">
Sign in at [supabase.com/dashboard](https://supabase.com/dashboard) and choose **New project**. Pick a name, a strong database password and the region closest to you. Wait about two minutes for it to start.
</Step>
<Step title="Create the tables">
Twiligent keeps its database layout as migration files in `supabase/migrations/`, and the Supabase CLI applies them. The CLI came with `npm install` in the cloned `twiligent` folder (see [What you need on your computer](/docs/self-host#what-you-need-on-your-computer)). Run these from that folder:
```bash
npx supabase login
npx supabase link --project-ref <project-id>
npm run db:check
npm run db:push
```
- `npx supabase login` opens the browser to sign in to Supabase. On a machine without a browser, set `SUPABASE_ACCESS_TOKEN` to an access token from **Account**, **Access Tokens** instead.
- The project ID is in **Project Settings**, **General**. It is also the part before `.supabase.co` in the project URL. No database password is needed.
- `npm run db:check` lists the migrations it will apply, and `npm run db:push` applies them.
This creates the four tables Twiligent uses and closes them to the browser. It also adds the checks that keep stored values valid, the keys that tie each post to its owner's accounts, and the indexes the app's lists use. `npm run db:status` shows each migration and whether it is applied.
<Callout type="note" title="Without the CLI">
Open **SQL Editor**, then run each file from `supabase/migrations/` in file name order, one at a time. Apply later files the same way when you update Twiligent, because the CLI does not know about migrations run in the editor.
</Callout>
</Step>
<Step title="Configure sign-in">
Open **Authentication**, then **Sign In / Providers**, then **Email**.
- Keep **Confirm email** on and set up [email verification codes](/docs/self-host/email-codes), so a password account only works once its owner enters a code sent to the address.
- If you cannot set up email codes yet, members who create a password account would wait for a code Supabase's own email does not contain. Turn off **Allow new users to sign up** first and add members yourself under **Authentication**, **Users**, **Add user**; only then turn off **Confirm email**. Never leave both open: anyone could then create a password account for an address that is not theirs.
- To keep the instance private, turn off **Allow new users to sign up** after you and your team have created accounts. Google and emailed codes then only sign in existing members.
The sign-in page's email field sends a 6-digit sign-in code. Without [email verification codes](/docs/self-host/email-codes), Supabase sends its own **Magic Link** email instead, which by default holds a link rather than a code; the link still signs the person in. To show the code as well, open **Authentication**, **Emails**, **Magic Link** and add `{{ .Token }}` to the template. Supabase's built-in email only sends a few messages an hour, so set up email verification codes, or have members use Google or a password.
</Step>
<Step title="Copy the project URL">
Open **Project Settings**, then **Data API** (or **Integrations**, **Data API**). Copy the **Project URL**, which looks like `https://abcdefgh.supabase.co`. It is used as `SUPABASE_URL` and `VITE_SUPABASE_URL`.
</Step>
<Step title="Copy the two keys">
Open **Project Settings**, then **API Keys**. Supabase shows either the new key format or the legacy one; both work.
| Key | Looks like | Used as | Safety |
| --- | --- | --- | --- |
| Publishable key (legacy: anon) | `sb_publishable_...` | `SUPABASE_ANON_KEY` and `VITE_SUPABASE_ANON_KEY` | <Badge>Safe in the browser</Badge> |
| Secret key (legacy: service_role) | `sb_secret_...` | `SUPABASE_SERVICE_KEY` | <Badge tone="secret">Server only</Badge> |
<Callout type="danger" title="Never put the secret key in the frontend">
The secret key can read and change every row in the database. It belongs only in the Worker's secrets and, if you use the backup scheduler, in GitHub Actions secrets.
</Callout>
</Step>
</Steps>
## Upgrading an existing instance
If you set up the tables with SQL from an older version of these docs or the README, including the `claimed_at` and `attempts` upgrade, link the CLI as above and run `npm run db:check`, then `npm run db:push`, before you deploy the new version of the Worker.
The first four migrations describe the tables as they were before migrations existed. They are safe to run on tables that already exist, and they bring every earlier setup to the same starting point: they add any missing columns and mark posts stuck in Publishing with no claim as failed, with a note to check Instagram first, because nothing recorded whether they went out. The migrations after them change the tables in small steps.
If a check stops the push because of an old row, the error names the rule. Fix that row in the **Table Editor** and run `npm run db:push` again.
### Why row level security with no policies
The backend uses the secret key, which bypasses row level security, and limits every query to the signed-in user itself. The browser never reads the tables; it only signs in with Supabase. So the migrations turn security on with no policies and also remove every permission the publishable key's roles had on the tables and on Twiligent's database functions. The public publishable key, which ships in the frontend, cannot read or change any table directly, and neither can a signed-in member's own token.
A policy that let members reach their own rows would still expose their raw Instagram tokens to the browser, and would let them write rows the backend refuses, such as a post on another member's account. Older setups had such policies; the migrations remove them.