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.

docs: record the signed-in cookie and the home page redirect

spacesdrive2a7ff2e76562
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f8cd9a2..1e2ac01 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -25,6 +25,7 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Fixed
- The sign-in page opens the dashboard when you are already signed in, so the public site's Sign in and Get started buttons no longer ask you to sign in again (#94)
+- The public site's home page opens the dashboard when you are signed in to the app; the docs stay readable (#96)
---
diff --git a/DECISIONS.md b/DECISIONS.md
index 51ec3fe..1b592e8 100644
--- a/DECISIONS.md
+++ b/DECISIONS.md
@@ -895,3 +895,22 @@ New row ids come from `crypto.randomUUID()` (`newRowId()` in `backend/lib/ids.ts
**Trade-offs:**
- Many more files per feature; the version numbers order them, and the names say what each holds.
- Migrations before the cut-over version stay as production recorded them; rewriting applied migrations would break the history in `supabase_migrations.schema_migrations`.
+
+## ADR-042: A signed-in cookie on the shared domain sends the public home page to the app
+
+**Date:** 2026-10-16
+**Status:** Accepted
+
+**Decision:** While a session exists, the app sets the cookie `twiligent_signed_in=1` on `twiligent.ujjwal.fyi` (`Path=/`, `SameSite=Lax`, `Secure`, 30 days, renewed on every load) and clears it as soon as the session ends. The first inline script in `site/index.html` sends the home page, and only the home page, to `https://app.twiligent.ujjwal.fyi/` before it paints when the cookie is present. The app writes the cookie only when it runs under `twiligent.ujjwal.fyi`.
+
+**Context:** A signed-in owner opening `https://twiligent.ujjwal.fyi/` saw the marketing page and had to choose Sign in to reach the dashboard (#96). The site and the app are separate origins (ADR-035), and the Supabase session lives in the app's localStorage, which the site cannot read.
+
+**Alternatives considered:**
+- Moving the Supabase session into a cookie on the shared domain. The site could then read the session itself, but the access and refresh tokens would be sent with every request to the site and readable by its scripts, for no gain beyond a redirect.
+- An iframe or `postMessage` probe of the app from the site. It loads the app on every visit to the home page and depends on third-party storage rules that browsers are tightening.
+- Changing only the site's buttons to Open dashboard. Still a click, which is what the owner asked to remove.
+
+**Trade-offs:**
+- The cookie is a hint, not proof: after a session ends in a way the app has not yet seen (a refresh token revoked elsewhere), the home page sends the visitor to the app once, which finds no session, clears the cookie and shows the sign-in page.
+- A signed-in visitor cannot see the marketing home page without signing out; the docs and other site pages are not redirected.
+- Self-hosted instances on other domains write no cookie, so their behaviour is unchanged; the domain is a constant, like the docs address in `frontend/src/lib/docs.ts`.
diff --git a/docs/architecture/data-flows/AUTHENTICATION.md b/docs/architecture/data-flows/AUTHENTICATION.md
index 159f37e..a7cc005 100644
--- a/docs/architecture/data-flows/AUTHENTICATION.md
+++ b/docs/architecture/data-flows/AUTHENTICATION.md
@@ -15,6 +15,8 @@
When the browser already holds a session, `/login` opens the dashboard (`/`) instead of the form, so the public site's Sign in and Get started buttons take a signed-in person straight in. `signInPageOutcome()` in `lib/signInPage.ts` decides it: the page renders nothing while the stored session loads, and a session created by a sign-in started on the page is left to that sign-in, so the password reset saves the new password before it navigates.
+The public site's home page (`https://twiligent.ujjwal.fyi/`) opens the dashboard too. The site is another origin and cannot read the session, so `AuthProvider` writes the cookie `twiligent_signed_in=1` on the shared domain whenever a session is present and clears it whenever it is not (`signedInCookie()` in `lib/signedInCookie.ts`: `Domain=twiligent.ujjwal.fyi`, 30 days renewed on every load, `SameSite=Lax`, `Secure`). The cookie says only that someone is signed in and carries no token; the API never reads it. It is written only when the app runs under `twiligent.ujjwal.fyi`, so self-hosted and local apps write nothing. See `docs/architecture/site/SITE.md` and ADR-042.
+
`?mode=signup` (the public site's Get started buttons) keeps the `start` view but shows the headline "Create your Twiligent account" and Google's "Sign up with Google". The default ways to join are Google and an emailed code, both of which create the account on first use; the password sign-up stays behind the password view for instances that do not email codes.
## Login Flow (Emailed Code, the Default)
diff --git a/docs/architecture/site/SITE.md b/docs/architecture/site/SITE.md
index b8cbd65..108ca95 100644
--- a/docs/architecture/site/SITE.md
+++ b/docs/architecture/site/SITE.md
@@ -26,7 +26,8 @@ The site does not use shadcn/ui, next-themes or Lucide; those belong to the app.
```
site/
- index.html Meta tags, favicons, font preloads, and the inline script that sets data-theme before paint
+ index.html Meta tags, favicons, font preloads, the inline script that opens the app for a signed-in visitor
+ on the home page, and the inline script that sets data-theme before paint
vite.config.ts MDX (before the React plugin), React, Tailwind, docsPlugin; @ alias to src/
build/
docsPlugin.ts Vite plugin: search index as virtual:docs-search, sitemap.xml and llms.txt in closeBundle
@@ -91,6 +92,8 @@ Fallback: the build has no top-level `404.html`, so Cloudflare Pages serves `ind
Links to the app use the constants in `src/lib/links.ts`: `SIGN_IN_URL` (`https://app.twiligent.ujjwal.fyi/login`) and `SIGN_UP_URL` (the same with `?mode=signup`, which shows the app's sign-up headline and Sign up with Google; an emailed code creates the account). Sign-up and sign-in only exist in the app.
+A visitor already signed in to the app skips the home page. The app's session lives in its own origin's storage, so the app also sets the cookie `twiligent_signed_in=1` on `twiligent.ujjwal.fyi` while a session exists and clears it when the session ends (`frontend/src/lib/signedInCookie.ts`; it holds no token). The first script in `index.html` sends `/` to `https://app.twiligent.ujjwal.fyi/` with `location.replace()` before the page paints when the cookie is there. Docs and every other path stay readable, and a stale cookie is cleared by the app the moment it finds no session (ADR-042).
+
## Docs Pipeline
**Pages.** Each page is `content/docs/<slug>.mdx`; `index.mdx` is the folder's own page (`content/docs/index.mdx` is `/docs`, `content/docs/self-host/index.mdx` is `/docs/self-host`). Every file starts with one line:
@@ -196,6 +199,7 @@ The product previews are React components drawn with the site's tokens, never sc
| `tests/docs/searchShared.test.ts` | `slugify()` turns headings into anchor ids |
| `tests/lib/chart.test.ts` | The value range is padded; points spread across the box; the smooth path passes through every point and never overshoots between two; the area closes to the baseline |
| `tests/lib/format.test.ts` | Full numbers get separators, short numbers use K and M and drop a zero decimal, rates keep one decimal |
+| `tests/homeRedirect.test.ts` | Runs the signed-in script from `index.html`: the home page opens the app only with `twiligent_signed_in=1`, and docs and other paths never redirect |
`content.test.ts` reads `nav.ts` as text, because `nav.ts` imports the generated JSX icons, which Node cannot load. The root `npm test`, `npm run typecheck` and `npm run build` include the site, so `ci.yml` checks it on every pull request.
diff --git a/docs/workflows/TESTING.md b/docs/workflows/TESTING.md
index 6d332fa..9a9a073 100644
--- a/docs/workflows/TESTING.md
+++ b/docs/workflows/TESTING.md
@@ -54,6 +54,8 @@ Tests never sit next to source files. Each workspace has a `tests/` folder that
| `frontend/src/lib/emailAddress.ts` | `frontend/tests/lib/emailAddress.test.ts` |
| `frontend/src/lib/googleIdentity.ts` | `frontend/tests/lib/googleIdentity.test.ts` |
| `frontend/src/lib/signInPage.ts` | `frontend/tests/lib/signInPage.test.ts` |
+| `frontend/src/lib/signedInCookie.ts` | `frontend/tests/lib/signedInCookie.test.ts` |
+| `site/index.html` (the signed-in redirect script) | `site/tests/homeRedirect.test.ts` |
| `frontend/src/features/analytics/overview/overviewStats.ts` | `frontend/tests/features/analytics/overview/overviewStats.test.ts` |
| `frontend/src/features/publishing/scheduleHelpers.ts` | `frontend/tests/features/publishing/scheduleHelpers.test.ts` |
| `site/src/docs/searchShared.ts` | `site/tests/docs/searchShared.test.ts` |
@@ -160,6 +162,7 @@ Open the app in a browser. For each changed area, test:
- [ ] Continue with Google signs in (only on an origin listed in the OAuth client's Authorized JavaScript origins); in dark mode the button is the app's outline button with no white square behind the G, and Tab focus shows its ring
- [ ] `/login?mode=signup` shows "Create your Twiligent account" and "Sign up with Google"
- [ ] Signed in, open `/login` or `/login?mode=signup` (or the public site's Sign in) -> Overview opens without the form; signed out, the form shows
+- [ ] Signed in, open `https://twiligent.ujjwal.fyi/` -> the app's Overview opens with no flash of the home page, while `/docs` still shows the docs; sign out, open it again -> the home page shows
- [ ] With the daily cap reached, Continue shows the warning "Email codes are paused until tomorrow" above Google, offering Google or the password
- [ ] Sign out -> redirects to login