Skip to content

Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.

feat(settings): five-step GitHub scheduling setup anyone can follow

spacesdrive66f4f70b279f
diff --git a/.github/workflows/publish-scheduled.yml b/.github/workflows/publish-scheduled.yml
index 5daa977..3147c48 100644
--- a/.github/workflows/publish-scheduled.yml
+++ b/.github/workflows/publish-scheduled.yml
@@ -9,7 +9,10 @@
#
# REQUIRED SECRETS (set in GitHub repo → Settings → Secrets → Actions):
# SUPABASE_URL - your Supabase project URL
-# SUPABASE_SERVICE_KEY - your Supabase service role key
+# SUPABASE_SERVICE_KEY - a Supabase secret key (sb_secret_...) or the legacy service_role key
+#
+# Step-by-step setup with direct links: Settings, Scheduled publishing in the app,
+# or docs/workflows/SCHEDULING_SETUP.md
on:
schedule:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bfecfc5..cae402b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -41,6 +41,8 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Added
**Redesign additions**
+- Scheduling setup rewritten as five plain steps with one button each, a check for each step, progress you can tick off, and fixes for common errors (`docs/workflows/SCHEDULING_SETUP.md`)
+- The GitHub publisher accepts Supabase's new `sb_secret_` keys as well as the legacy `service_role` key
- Scheduled publishing guide in Settings: how it works for users, and administrator setup for the server cron and the optional GitHub Actions backup, with direct links to the repository's secrets and workflow pages
- Publish explains when scheduled posts go out and warns when posts are overdue, with the administrator contact
- Instagram tester guide wherever Instagram is connected: email the administrator, accept the invite, then connect
diff --git a/README.md b/README.md
index d7ccaf5..cd876b0 100644
--- a/README.md
+++ b/README.md
@@ -328,22 +328,15 @@ Both schedulers write to the same `scheduled_posts` table in Supabase. A `publis
### Setup (GitHub Actions fallback only)
-The Cloudflare Worker cron requires no additional setup. To enable the GitHub Actions fallback:
+The Cloudflare Worker cron requires no additional setup. The GitHub Actions fallback takes about 5 minutes:
-**Step 1 - Add repository secrets**
+1. **Fork** this repository to your GitHub account.
+2. **Copy two values from Supabase:** the project URL (Integrations, Data API) and a secret key (Settings, API Keys; `sb_secret_...`, or the legacy `service_role` key).
+3. **Add them as repository secrets** named `SUPABASE_URL` and `SUPABASE_SERVICE_KEY` (Settings, Secrets and variables, Actions).
+4. **Switch on the workflow** in the Actions tab, including **Instagram Scheduled Publisher**.
+5. **Run it once** with Run workflow and check for a green tick.
-Go to your GitHub repo, then **Settings**, then **Secrets and variables**, then **Actions**, then **New repository secret**:
-
-| Name | Value |
-|---|---|
-| `SUPABASE_URL` | Your Supabase project URL |
-| `SUPABASE_SERVICE_KEY` | Your Supabase service role key |
-
-**Step 2 - Enable Actions**
-
-Go to your repo then **Actions** and enable workflows if prompted. The `Instagram Scheduled Publisher` workflow starts automatically on the cron schedule.
-
-**Free tier note:** Public repos get unlimited GitHub Actions minutes. For private repos (2,000 min per month limit), change the cron in `.github/workflows/publish-scheduled.yml` from `*/15` to `*/30` to stay within limits.
+Full walkthrough with what to expect at each step and fixes for common errors: [docs/workflows/SCHEDULING_SETUP.md](docs/workflows/SCHEDULING_SETUP.md). The same guide is in the app under Settings, Scheduled publishing, with direct links once you enter your GitHub username.
---
diff --git a/claude.md b/claude.md
index f96f648..2daa0df 100644
--- a/claude.md
+++ b/claude.md
@@ -84,6 +84,7 @@ docs/
TESTING.md Test types, commands, pass criteria
GIT.md Commit format, branch rules, changelog
DEPLOYMENT.md Backend deploy, frontend deploy, verification
+ SCHEDULING_SETUP.md Five-step GitHub Actions scheduling setup for self-hosters
features/
NEW_ANALYTICS_PAGE.md Add analytics view for a new platform
NEW_API_ENDPOINT.md Add a route to the Hono backend
diff --git a/docs/architecture/data-flows/SCHEDULING.md b/docs/architecture/data-flows/SCHEDULING.md
index 78f88df..8c63760 100644
--- a/docs/architecture/data-flows/SCHEDULING.md
+++ b/docs/architecture/data-flows/SCHEDULING.md
@@ -78,7 +78,8 @@ Both schedulers implement the same logic:
- No personal access token is needed. The workflow only reads and updates Supabase.
- Private repositories: a 15-minute schedule exceeds the 2,000 free Actions minutes a month; use `*/30 * * * *`.
-The same steps are shown in the app under Settings, Scheduled publishing, with direct links once the repository owner and name are saved.
+Step-by-step instructions for a person setting this up: `docs/workflows/SCHEDULING_SETUP.md`, also shown in the app under Settings, Scheduled publishing with direct links once a GitHub username is saved.
+- `SUPABASE_SERVICE_KEY` can be a new secret key (`sb_secret_...`, sent on the `apikey` header only) or the legacy `service_role` JWT (sent on `apikey` and `Authorization`).
## What users see
diff --git a/docs/workflows/SCHEDULING_SETUP.md b/docs/workflows/SCHEDULING_SETUP.md
new file mode 100644
index 0000000..0a55742
--- /dev/null
+++ b/docs/workflows/SCHEDULING_SETUP.md
@@ -0,0 +1,69 @@
+# Set Up Your Own Scheduling With GitHub
+
+GitHub can check your scheduled Instagram posts every 15 minutes and publish the ones that are due, for free. It runs alongside the server's own scheduler as a backup, so posts still go out if the server is paused. You set it up once. It takes about 5 minutes.
+
+The same steps are in the app under **Settings, Scheduled publishing**, where typing your GitHub username turns every step into a direct link.
+
+**You need:** a free GitHub account, and access to the Supabase project this Twiligent uses.
+
+---
+
+## Step 1. Make your own copy of Twiligent
+
+1. Open https://github.com/spacesdrive/twiligent/fork
+2. Choose **Create fork**. Keep it public, because GitHub runs public repositories for free.
+
+**It worked if** you see `twiligent` under your own GitHub username.
+
+## Step 2. Copy two values from Supabase
+
+1. **Project URL.** In Supabase, open your project, then **Integrations, Data API**. It looks like `https://abcdefgh.supabase.co`.
+2. **Secret key.** Open **Settings, API Keys** and copy a secret key. It starts with `sb_secret_`. If your project only shows legacy keys, copy **service_role** instead.
+
+The secret key can read and change all your data. Paste it only into GitHub secrets in the next step, never into code, chat or email.
+
+**It worked if** you have both values ready to paste.
+
+## Step 3. Save the two values as secrets in your copy
+
+1. In your copy on GitHub, open **Settings, Secrets and variables, Actions** (`https://github.com/YOUR-USERNAME/twiligent/settings/secrets/actions`).
+2. Choose **New repository secret**, type the name exactly, paste the value, and choose **Add secret**. Do it twice:
+
+| Name | Value |
+|---|---|
+| `SUPABASE_URL` | The project URL from step 2 |
+| `SUPABASE_SERVICE_KEY` | The secret key from step 2 |
+
+**It worked if** both names appear in the Repository secrets list.
+
+## Step 4. Switch on the publisher
+
+GitHub switches workflows off in new copies.
+
+1. Open the **Actions** tab of your copy.
+2. Choose **I understand my workflows, go ahead and enable them**.
+3. Choose **Instagram Scheduled Publisher** in the list on the left. If a yellow banner says it is disabled, choose **Enable workflow**.
+
+**It worked if** Instagram Scheduled Publisher is listed with no disabled warning.
+
+## Step 5. Run it once to test
+
+1. On the Instagram Scheduled Publisher page, choose **Run workflow**, then the green **Run workflow** button.
+2. Refresh after a few seconds and open the new run.
+
+**It worked if** the run shows a green tick after about a minute. A log line saying "No posts due for publishing" is fine.
+
+| What you see | What it means | Fix |
+|---|---|---|
+| Red cross, "Missing SUPABASE_URL or SUPABASE_SERVICE_KEY" | A secret name is misspelled | Check the names in step 3 |
+| Red cross, "Supabase GET ... 401" | The secret key is wrong or cut short | Copy the key again in step 2 and replace the secret |
+| No Run workflow button | The workflow is still switched off | Repeat step 4 |
+
+---
+
+## After setup
+
+- GitHub checks every 15 minutes. You do not need to keep anything open.
+- The server scheduler and this workflow can run at the same time. Each post is claimed by whichever runs first, so it is published once.
+- If nothing changes in your copy for 60 days, GitHub pauses the schedule and emails you. Repeat step 4.
+- A private copy uses GitHub's free minutes (2,000 a month), and a run every 15 minutes uses more than that. Keep your copy public, or change `*/15 * * * *` to `*/30 * * * *` in `.github/workflows/publish-scheduled.yml`.
diff --git a/frontend/src/features/settings/SchedulingSetupGuide.jsx b/frontend/src/features/settings/SchedulingSetupGuide.jsx
new file mode 100644
index 0000000..31d02bc
--- /dev/null
+++ b/frontend/src/features/settings/SchedulingSetupGuide.jsx
@@ -0,0 +1,205 @@
+import React, { useEffect, useState } from 'react';
+import { GitFork, KeyRound, Lock, Power, PlayCircle, Check, Copy, ExternalLink, Save } from 'lucide-react';
+import { Button } from '@/components/ui/button';
+import { Input } from '@/components/ui/input';
+import { Spinner } from '@/components/ui/spinner';
+import SurfaceBox from '@/components/SurfaceBox';
+import { cn } from '@/lib/utils';
+
+const UPSTREAM_REPO = 'spacesdrive/twiligent';
+const SUPABASE_KEYS_URL = 'https://supabase.com/dashboard/project/_/settings/api-keys';
+const SUPABASE_URL_PAGE = 'https://supabase.com/dashboard/project/_/integrations/data_api/overview';
+const PROGRESS_KEY = 'twiligent.schedulingSetup.done';
+
+function readProgress() {
+ try { return JSON.parse(localStorage.getItem(PROGRESS_KEY)) || {}; } catch { return {}; }
+}
+
+function CopyChip({ text }) {
+ const [copied, setCopied] = useState(false);
+ return (
+ <button
+ type="button"
+ onClick={async () => {
+ try { await navigator.clipboard.writeText(text); setCopied(true); setTimeout(() => setCopied(false), 1500); } catch { setCopied(false); }
+ }}
+ className="inline-flex h-7 items-center gap-1.5 rounded-control border border-line-control bg-surface px-2.5 font-mono text-small text-ink transition-colors hover:bg-surface-hover"
+ aria-label={copied ? `${text} copied` : `Copy ${text}`}
+ >
+ {text}
+ {copied ? <Check className="size-3.5 text-success" /> : <Copy className="size-3.5 text-ink-faint" />}
+ </button>
+ );
+}
+
+function LinkButton({ href, children, disabled, variant = 'outline' }) {
+ if (disabled) {
+ return <Button variant={variant} size="sm" disabled>{children}</Button>;
+ }
+ return (
+ <Button variant={variant} size="sm" render={<a href={href} target="_blank" rel="noopener noreferrer" />}>
+ {children}
+ <ExternalLink data-icon="inline-end" />
+ </Button>
+ );
+}
+
+function Step({ number, icon, title, done, onToggle, children, check }) {
+ const Icon = icon;
+ return (
+ <li className={cn('flex gap-4 rounded-card border p-4 transition-colors', done ? 'border-success/30 bg-success-soft/40' : 'border-line')}>
+ <div className="flex flex-col items-center gap-2">
+ <span className={cn(
+ 'flex size-9 shrink-0 items-center justify-center rounded-full',
+ done ? 'bg-success text-ink-inverse' : 'bg-surface-sunken text-ink-muted',
+ )}>
+ {done ? <Check className="size-4" strokeWidth={2.5} /> : <Icon className="size-4 stroke-[1.75]" />}
+ </span>
+ </div>
+ <div className="flex min-w-0 flex-1 flex-col gap-3">
+ <div className="flex flex-wrap items-start justify-between gap-2">
+ <p className="text-sm font-semibold text-ink"><span className="text-ink-faint">Step {number}. </span>{title}</p>
+ <label className="flex cursor-pointer items-center gap-2 text-small text-ink-muted select-none">
+ <input type="checkbox" checked={done} onChange={onToggle} className="size-4 accent-[var(--brand)]" />
+ Done
+ </label>
+ </div>
+ <div className="flex flex-col gap-3 text-sm text-ink-muted [&_strong]:font-semibold [&_strong]:text-ink">{children}</div>
+ {check && (
+ <p className="flex items-start gap-1.5 text-small text-success">
+ <Check className="mt-0.5 size-3.5 shrink-0" />
+ <span><span className="font-semibold">It worked if</span> {check}</span>
+ </p>
+ )}
+ </div>
+ </li>
+ );
+}
+
+export default function SchedulingSetupGuide({ owner, repo, onOwnerChange, onRepoChange, onSave, saving }) {
+ const [done, setDone] = useState(readProgress);
+
+ useEffect(() => {
+ try { localStorage.setItem(PROGRESS_KEY, JSON.stringify(done)); } catch { /* progress is a convenience only */ }
+ }, [done]);
+
+ const toggle = key => () => setDone(prev => ({ ...prev, [key]: !prev[key] }));
+ const user = owner.trim();
+ const name = (repo || 'twiligent').trim();
+ const base = user ? `https://github.com/${user}/${name}` : null;
+ const completed = ['fork', 'supabase', 'secrets', 'enable', 'test'].filter(k => done[k]).length;
+
+ return (
+ <SurfaceBox
+ title="Set up your own scheduling with GitHub"
+ subheader="About 5 minutes. You need a free GitHub account and access to the Supabase project this Twiligent uses."
+ secondary={<span className="text-small text-ink-faint tabular-nums">{completed} of 5 done</span>}
+ >
+ <div className="flex flex-col gap-5">
+ <p className="text-sm text-ink-muted">
+ GitHub will check your scheduled posts every 15 minutes and publish the ones that are due, for free. This is a backup for the server, so posts still go out if the server is ever paused. You do this once.
+ </p>
+
+ <form onSubmit={onSave} className="flex flex-col gap-2 rounded-field bg-surface-sunken/60 p-4">
+ <label htmlFor="gh-user" className="text-sm font-medium text-ink">Your GitHub username</label>
+ <p className="text-caption text-ink-faint">Type it once and every button below opens the right page in your GitHub.</p>
+ <div className="flex flex-wrap gap-2">
+ <Input id="gh-user" value={owner} onChange={e => onOwnerChange(e.target.value)} placeholder="your-github-username" autoComplete="off" className="max-w-xs flex-1 bg-surface-raised" />
+ <Button type="submit" variant="outline" disabled={saving || !user}>
+ {saving ? <Spinner className="size-4" /> : <Save data-icon="inline-start" />}
+ Save
+ </Button>
+ </div>
+ <details className="text-caption text-ink-faint">
+ <summary className="cursor-pointer select-none">Renamed your copy?</summary>
+ <div className="mt-2 flex items-center gap-2">
+ <label htmlFor="gh-repo" className="shrink-0">Repository name</label>
+ <Input id="gh-repo" value={repo} onChange={e => onRepoChange(e.target.value)} placeholder="twiligent" autoComplete="off" className="h-(--control-h-sm) max-w-48 bg-surface-raised" />
+ </div>
+ </details>
+ </form>
+
+ <ol className="flex flex-col gap-3">
+ <Step
+ number={1}
+ icon={GitFork}
+ title="Make your own copy of Twiligent on GitHub"
+ done={!!done.fork}
+ onToggle={toggle('fork')}
+ check="you see the twiligent repository under your own GitHub username."
+ >
+ <p>Open the Twiligent repository and choose <strong>Fork</strong>, then <strong>Create fork</strong>. Keep it public: GitHub runs public repositories for free.</p>
+ <div><LinkButton href={`https://github.com/${UPSTREAM_REPO}/fork`}>Fork on GitHub</LinkButton></div>
+ </Step>
+
+ <Step
+ number={2}
+ icon={KeyRound}
+ title="Copy two values from Supabase"
+ done={!!done.supabase}
+ onToggle={toggle('supabase')}
+ check="you have the project URL and the secret key ready to paste."
+ >
+ <p><strong>Project URL.</strong> In Supabase, open your project, then <strong>Integrations, Data API</strong>. It looks like <code className="font-mono text-small text-ink">https://abcdefgh.supabase.co</code>.</p>
+ <p><strong>Secret key.</strong> Open <strong>Settings, API Keys</strong> and copy a secret key (it starts with <code className="font-mono text-small text-ink">sb_secret_</code>). If your project only shows legacy keys, copy <strong>service_role</strong> instead.</p>
+ <p className="flex items-start gap-1.5 text-small text-warning"><Lock className="mt-0.5 size-3.5 shrink-0" />The secret key can read and change all your data. Paste it only into GitHub secrets in the next step, never into code, chat or email.</p>
+ <div className="flex flex-wrap gap-2">
+ <LinkButton href={SUPABASE_URL_PAGE}>Open Data API</LinkButton>
+ <LinkButton href={SUPABASE_KEYS_URL}>Open API Keys</LinkButton>
+ </div>
+ </Step>
+
+ <Step
+ number={3}
+ icon={Lock}
+ title="Save the two values as secrets in your copy"
+ done={!!done.secrets}
+ onToggle={toggle('secrets')}
+ check="both names appear in the Repository secrets list."
+ >
+ <p>On the secrets page choose <strong>New repository secret</strong>. Type the name exactly as shown, paste the value, and choose <strong>Add secret</strong>. Do it twice:</p>
+ <div className="flex flex-col gap-2">
+ <div className="flex flex-wrap items-center gap-2"><CopyChip text="SUPABASE_URL" /><span className="text-small">with the project URL</span></div>
+ <div className="flex flex-wrap items-center gap-2"><CopyChip text="SUPABASE_SERVICE_KEY" /><span className="text-small">with the secret key</span></div>
+ </div>
+ <div><LinkButton href={base ? `${base}/settings/secrets/actions` : ''} disabled={!base}>{base ? 'Open secrets page' : 'Enter your GitHub username first'}</LinkButton></div>
+ </Step>
+
+ <Step
+ number={4}
+ icon={Power}
+ title="Switch on the publisher"
+ done={!!done.enable}
+ onToggle={toggle('enable')}
+ check="Instagram Scheduled Publisher is listed on the left with no disabled warning."
+ >
+ <p>GitHub switches workflows off in new copies. Open the <strong>Actions</strong> tab and choose <strong>I understand my workflows, go ahead and enable them</strong>. Then choose <strong>Instagram Scheduled Publisher</strong> in the list on the left, and if a yellow banner says it is disabled, choose <strong>Enable workflow</strong>.</p>
+ <div><LinkButton href={base ? `${base}/actions` : ''} disabled={!base}>{base ? 'Open Actions' : 'Enter your GitHub username first'}</LinkButton></div>
+ </Step>
+
+ <Step
+ number={5}
+ icon={PlayCircle}
+ title="Run it once to test"
+ done={!!done.test}
+ onToggle={toggle('test')}
+ check="the run shows a green tick after about a minute. The log saying “No posts due for publishing” is fine."
+ >
+ <p>On the publisher page choose <strong>Run workflow</strong>, then the green <strong>Run workflow</strong> button. Refresh the page after a few seconds and open the new run.</p>
+ <p>A red cross with <strong>Missing SUPABASE_URL or SUPABASE_SERVICE_KEY</strong> means a secret name is misspelled; fix it in step 3. Any other red cross usually means the secret key was pasted incompletely.</p>
+ <div><LinkButton href={base ? `${base}/actions/workflows/publish-scheduled.yml` : ''} disabled={!base}>{base ? 'Open the publisher' : 'Enter your GitHub username first'}</LinkButton></div>
+ </Step>
+ </ol>
+
+ <div className="flex flex-col gap-2 rounded-field border border-line p-4">
+ <p className="text-sm font-semibold text-ink">That is it</p>
+ <p className="text-sm text-ink-muted">GitHub now checks every 15 minutes. You do not need to keep anything open. Two things to know:</p>
+ <ul className="flex list-disc flex-col gap-1 pl-5 text-sm text-ink-muted marker:text-ink-faint">
+ <li>If nothing changes in your copy for 60 days, GitHub pauses the schedule and emails you. Repeat step 4 to switch it back on.</li>
+ <li>If you made your copy private, GitHub's free minutes run out. Keep it public, or ask your administrator to lower the frequency to every 30 minutes.</li>
+ </ul>
+ </div>
+ </div>
+ </SurfaceBox>
+ );
+}
diff --git a/frontend/src/features/settings/Settings.jsx b/frontend/src/features/settings/Settings.jsx
index d7208fa..ac7aa48 100644
--- a/frontend/src/features/settings/Settings.jsx
+++ b/frontend/src/features/settings/Settings.jsx
@@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react';
import { useSmoothTheme } from '@/hooks/use-smooth-theme';
import { useLocation } from 'react-router-dom';
import {
- RefreshCw, CheckCircle2, AlertTriangle, ExternalLink, Copy, Check, Save, Sun, Moon, Monitor, Activity, Clock,
+ RefreshCw, CheckCircle2, AlertTriangle, ExternalLink, Sun, Moon, Monitor, Activity, Clock,
} from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
@@ -15,54 +15,20 @@ import PageHeader from '@/components/PageHeader';
import SurfaceBox from '@/components/SurfaceBox';
import { FieldRow } from '@/components/DetailPanel';
import InstagramTesterNotice from '@/components/InstagramTesterNotice';
+import SchedulingSetupGuide from './SchedulingSetupGuide';
import { ADMIN_EMAIL, adminMailto } from '@/lib/contact';
import { useAppContext } from '../../context/AppContext';
import { api } from '../../services/api';
import { cn } from '@/lib/utils';
-const WORKFLOW_FILE = '.github/workflows/publish-scheduled.yml';
-const SECRET_NAMES = [
- { name: 'SUPABASE_URL', hint: 'Your Supabase project URL. Supabase dashboard, Project Settings, API.' },
- { name: 'SUPABASE_SERVICE_KEY', hint: 'The service_role key from the same page. It can read and write every table, so it goes only into GitHub secrets, never into code or chat.' },
-];
-
-function repoLinks(owner, repo) {
- if (!owner || !repo) return null;
- const base = `https://github.com/${owner.trim()}/${repo.trim()}`;
- return {
- newSecret: `${base}/settings/secrets/actions/new`,
- actions: `${base}/actions`,
- workflow: `${base}/actions/workflows/publish-scheduled.yml`,
- };
-}
-
const LINKS = [
- { label: 'Supabase API settings', href: 'https://supabase.com/dashboard/project/_/settings/api' },
+ { label: 'Supabase API keys', href: 'https://supabase.com/dashboard/project/_/settings/api-keys' },
{ label: 'Cloudinary console', href: 'https://cloudinary.com/console' },
{ label: 'Google Cloud credentials', href: 'https://console.cloud.google.com/apis/credentials' },
{ label: 'Meta app dashboard', href: 'https://developers.facebook.com/apps' },
{ label: 'Cloudflare dashboard', href: 'https://dash.cloudflare.com' },
];
-function CopyButton({ text }) {
- const [copied, setCopied] = useState(false);
- const handleCopy = async () => {
- try {
- await navigator.clipboard.writeText(text);
- setCopied(true);
- setTimeout(() => setCopied(false), 2000);
- } catch {
- setCopied(false);
- }
- };
- return (
- <Button variant="ghost" size="xs" onClick={handleCopy} aria-label={copied ? 'Copied' : `Copy ${text}`}>
- {copied ? <Check className="text-success" /> : <Copy />}
- {copied ? 'Copied' : 'Copy'}
- </Button>
- );
-}
-
function Steps({ steps }) {
return (
<ol className="flex flex-col gap-4">
@@ -154,8 +120,8 @@ export default function Settings() {
e.preventDefault();
setGhSaving(true);
try {
- await api.saveGithubSettings({ repoOwner: ghRepoOwner.trim(), repoName: ghRepoName.trim(), branch: 'main' });
- showToast('Repository saved. The links in the guide now point to it.');
+ await api.saveGithubSettings({ repoOwner: ghRepoOwner.trim(), repoName: (ghRepoName || 'twiligent').trim(), branch: 'main' });
+ showToast('GitHub username saved. The buttons in the guide now open your copy.');
} catch (err) {
showToast(`Couldn't save the repository. ${err.message}`, 'error');
} finally {
@@ -163,47 +129,6 @@ export default function Settings() {
}
};
- const links = repoLinks(ghRepoOwner, ghRepoName);
- const adminSteps = [
- {
- title: 'Check the server scheduler',
- body: <>The Cloudflare Worker publishes due posts every 15 minutes. It is set up by deploying the backend (the cron is in <code className="font-mono text-small">backend/wrangler.toml</code>). In the Cloudflare dashboard, open Workers and Pages, then the twiligent Worker, then Settings, and confirm the trigger <code className="font-mono text-small">*/15 * * * *</code> is listed. Nothing else is required for scheduling to work.</>,
- },
- {
- title: 'Optional: add the GitHub Actions backup',
- body: <>The repository includes <code className="font-mono text-small">{WORKFLOW_FILE}</code>, which publishes due posts if the Worker cron is paused or failing. It needs your own copy of the repository on GitHub (a fork or a clone you pushed). Enter it below to get direct links.</>,
- },
- {
- title: 'Add two repository secrets',
- body: <>In the repository on GitHub, open Settings, then Secrets and variables, then Actions, then New repository secret. {links && <a href={links.newSecret} target="_blank" rel="noopener noreferrer">Open the new secret page</a>}</>,
- extra: (
- <div className="mt-1.5 flex flex-col gap-2">
- {SECRET_NAMES.map(secret => (
- <div key={secret.name} className="flex flex-col gap-1 rounded-control border border-line bg-surface-sunken px-3 py-2">
- <div className="flex items-center gap-2">
- <code className="flex-1 font-mono text-small text-ink">{secret.name}</code>
- <CopyButton text={secret.name} />
- </div>
- <p className="text-caption text-ink-faint">{secret.hint}</p>
- </div>
- ))}
- </div>
- ),
- },
- {
- title: 'Turn on the workflow',
- body: <>Open the Actions tab. Forks start with workflows switched off: choose the button to enable them. Then open <strong>Instagram Scheduled Publisher</strong> and choose Enable workflow if GitHub shows it as disabled. {links && <a href={links.workflow} target="_blank" rel="noopener noreferrer">Open the workflow</a>}</>,
- },
- {
- title: 'Run it once to test',
- body: 'On the workflow page choose Run workflow. Open the run: the log ends with "No posts due for publishing" or lists the posts it published. A red run with "Missing SUPABASE_URL or SUPABASE_SERVICE_KEY" means a secret name is misspelled.',
- },
- {
- title: 'Mind the free minutes on private repositories',
- body: <>Public repositories run Actions for free. Private ones get 2,000 minutes a month, and a run every 15 minutes uses more than that. For a private repository, change the cron in <code className="font-mono text-small">{WORKFLOW_FILE}</code> to <code className="font-mono text-small">*/30 * * * *</code>. GitHub also pauses scheduled workflows in public repositories after 60 days without commits; re-enable it from the Actions tab if that happens.</>,
- },
- ];
-
const handleTest = async () => {
setTesting(true);
setTestResult(null);
@@ -278,7 +203,7 @@ export default function Settings() {
<SettingsSection
id="scheduling"
title="Scheduled publishing"
- description="How scheduled Instagram posts go out, and what the person who runs this instance sets up once."
+ description="How scheduled Instagram posts go out, and how to set up your own GitHub publisher in five steps."
>
<SurfaceBox title="How it works for you">
<Steps steps={[
@@ -296,32 +221,14 @@ export default function Settings() {
</div>
</SurfaceBox>
- <SurfaceBox title="Set up for administrators" subheader="Only the person who deploys this Twiligent instance does this, once.">
- <form className="mb-6 flex flex-col gap-4" onSubmit={handleSaveGithub}>
- <div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
- <FieldRow label="GitHub repository owner" hint="Your GitHub username or organisation" htmlFor="gh-owner">
- <Input id="gh-owner" placeholder="your-username" value={ghRepoOwner} onChange={e => setGhRepoOwner(e.target.value)} autoComplete="off" />
- </FieldRow>
- <FieldRow label="Repository name" hint="Your copy of the Twiligent repository" htmlFor="gh-repo">
- <Input id="gh-repo" placeholder="twiligent" value={ghRepoName} onChange={e => setGhRepoName(e.target.value)} autoComplete="off" />
- </FieldRow>
- </div>
- <div className="flex flex-wrap items-center gap-2">
- <Button type="submit" variant="outline" disabled={ghSaving || !ghRepoOwner.trim() || !ghRepoName.trim()}>
- {ghSaving ? <Spinner className="size-4" /> : <Save data-icon="inline-start" />}
- {ghSaving ? 'Saving' : 'Save repository'}
- </Button>
- {links && (
- <Button variant="ghost" render={<a href={links.actions} target="_blank" rel="noopener noreferrer" />}>
- <ExternalLink data-icon="inline-start" />Open Actions
- </Button>
- )}
- </div>
- <p className="text-caption text-ink-faint">No personal access token is needed. Scheduling never writes to GitHub; the workflow only reads due posts from Supabase.</p>
- </form>
- <Steps steps={adminSteps} />
- <p className="mt-5 text-caption text-ink-faint">The Worker and the workflow can run side by side. Each post is claimed by whichever runs first, so it is never published twice.</p>
- </SurfaceBox>
+ <SchedulingSetupGuide
+ owner={ghRepoOwner}
+ repo={ghRepoName}
+ onOwnerChange={setGhRepoOwner}
+ onRepoChange={setGhRepoName}
+ onSave={handleSaveGithub}
+ saving={ghSaving}
+ />
</SettingsSection>
<SettingsSection id="platforms" title="Platform requirements" description="What each platform needs before it can be added.">
diff --git a/scripts/publish-scheduled.js b/scripts/publish-scheduled.js
index 1c2fe4a..2e8ab93 100644
--- a/scripts/publish-scheduled.js
+++ b/scripts/publish-scheduled.js
@@ -7,7 +7,7 @@
*
* Required GitHub Secrets:
* SUPABASE_URL - your Supabase project URL
- * SUPABASE_SERVICE_KEY - your Supabase service role key (bypasses RLS)
+ * SUPABASE_SERVICE_KEY - a Supabase secret key (sb_secret_...) or the legacy service_role key
*/
const SUPABASE_URL = (process.env.SUPABASE_URL || '').replace(/[^\x20-\x7E]/g, '').trim();
@@ -21,9 +21,11 @@ if (!SUPABASE_URL || !SUPABASE_SERVICE_KEY) {
// ─── Supabase REST helpers (no SDK, native fetch only) ────────────────────────
+// Legacy service_role keys are JWTs and go in both headers. New sb_secret_ keys are not JWTs
+// and Supabase expects them on apikey only.
const sbHeaders = {
'apikey': SUPABASE_SERVICE_KEY,
- 'Authorization': `Bearer ${SUPABASE_SERVICE_KEY}`,
+ ...(SUPABASE_SERVICE_KEY.startsWith('eyJ') ? { 'Authorization': `Bearer ${SUPABASE_SERVICE_KEY}` } : {}),
'Content-Type': 'application/json',
};