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.

fix(site): open the dashboard from the home page when signed in

spacesdrive80f6d1d8bb47
diff --git a/site/index.html b/site/index.html
index 14b5e50..1e4250c 100644
--- a/site/index.html
+++ b/site/index.html
@@ -3,6 +3,13 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
+ <script>
+ // the app leaves this cookie on the shared domain while someone is signed in (frontend/src/lib/signedInCookie.ts),
+ // so the home page opens the dashboard before it paints; docs and other pages stay readable
+ if (location.pathname === '/' && /(?:^|;\s*)twiligent_signed_in=1(?:;|$)/.test(document.cookie)) {
+ location.replace('https://app.twiligent.ujjwal.fyi/');
+ }
+ </script>
<title>Twiligent: every channel, folded into one clear picture</title>
<meta name="description" content="Twiligent puts your YouTube, Instagram and Reddit numbers side by side, publishes and schedules your Instagram posts, and runs on accounts you own." />
<link rel="icon" href="/brand/twiligent-favicon.svg" type="image/svg+xml" />
diff --git a/site/tests/homeRedirect.test.ts b/site/tests/homeRedirect.test.ts
new file mode 100644
index 0000000..02bdd67
--- /dev/null
+++ b/site/tests/homeRedirect.test.ts
@@ -0,0 +1,32 @@
+import { test } from 'node:test';
+import assert from 'node:assert/strict';
+import { readFileSync } from 'node:fs';
+import { runInNewContext } from 'node:vm';
+
+// the inline script in index.html that runs before the first paint
+const html = readFileSync(new URL('../index.html', import.meta.url), 'utf8');
+const script = html.match(/<script>\s*(\/\/ the app leaves[\s\S]*?)<\/script>/)?.[1];
+
+function visit(pathname: string, cookie: string): string | null {
+ assert.ok(script, 'index.html has the signed-in redirect script');
+ let target: string | null = null;
+ runInNewContext(script, { document: { cookie }, location: { pathname, replace: (url: string) => (target = url) } });
+ return target;
+}
+
+test('the home page opens the dashboard for someone signed in to the app', () => {
+ assert.equal(visit('/', 'twiligent_signed_in=1'), 'https://app.twiligent.ujjwal.fyi/');
+ assert.equal(visit('/', 'twiligent-theme=dark; twiligent_signed_in=1'), 'https://app.twiligent.ujjwal.fyi/');
+});
+
+test('the home page stays for everyone else', () => {
+ for (const cookie of ['', 'twiligent_signed_in=', 'twiligent_signed_in=0', 'other_twiligent_signed_in=1']) {
+ assert.equal(visit('/', cookie), null, cookie);
+ }
+});
+
+test('docs and other pages stay readable when signed in', () => {
+ for (const pathname of ['/docs', '/docs/use/automations', '/privacy']) {
+ assert.equal(visit(pathname, 'twiligent_signed_in=1'), null, pathname);
+ }
+});