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: Sign in with Google setup and auth flow

spacesdrive844146ba2efe
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 94996c1..7bac1b5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,10 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Added
+**Sign in with Google**
+- Continue with Google on the sign-in page, using Google's own button and a nonce-checked ID token sent to Supabase; shown only when `VITE_GOOGLE_CLIENT_ID` is set
+- Docs page for administrators: branding, audience, scopes, client, Supabase provider and brand verification
+
**Documentation site at `/docs`**
- Public documentation built into the app, laid out like a modern developer docs site: section tabs, grouped sidebar, "On this page" outline with scroll tracking, search with `/` or Ctrl K, previous and next links, copy-page and copy-code buttons, light and dark themes and a phone layout
- Separate paths for members (sign in, connect accounts, analytics, publishing, tracked content, troubleshooting) and administrators (Supabase, YouTube, Instagram, Cloudinary, Redis, backend and frontend deploys, GitHub automation, launch checklist)
diff --git a/DECISIONS.md b/DECISIONS.md
index b78d18b..8a41745 100644
--- a/DECISIONS.md
+++ b/DECISIONS.md
@@ -574,3 +574,19 @@ Records every significant architectural decision, the alternatives considered, a
- Docs ship with each frontend deploy, so they always match the deployed version, but cannot be updated without a frontend deploy.
- Each section is one code-split chunk, so the docs add nothing to the dashboard's initial load.
+---
+
+## ADR-027: Sign in with Google through Google's button and an ID token, not the OAuth redirect
+
+**Date:** 2026-10-13
+**Status:** Accepted
+
+**Decision:** The login page renders Google Identity Services' own button. The returned ID token goes to `supabase.auth.signInWithIdToken` with a nonce: Google gets the SHA-256 of a random value, Supabase gets the raw value and checks they match. The button only appears when `VITE_GOOGLE_CLIENT_ID` is set. The frontend moves to a custom domain on the administrator's verified domain.
+
+**Context:** Supabase's standard Google flow (`signInWithOAuth`) redirects through `<project-ref>.supabase.co/auth/v1/callback`. Google brand verification, needed to show the app name and logo on the sign-in screen, requires every domain in the client's configuration to be verified in Search Console, which a `supabase.co` subdomain cannot be. The alternative, a Supabase custom domain for the auth endpoint, needs a paid plan and add-on.
+
+**Trade-offs:**
+- Loads one third-party script (`accounts.google.com/gsi/client`) on the login page only, on demand. No npm dependency.
+- The button is rendered by Google in an iframe, so its styling is limited to Google's options (theme follows the app theme).
+- Self-hosters on `pages.dev` can still use it, but cannot get brand verification until they add a custom domain.
+
diff --git a/README.md b/README.md
index 6b6a833..d4f66b2 100644
--- a/README.md
+++ b/README.md
@@ -286,6 +286,8 @@ VITE_SUPABASE_ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
VITE_API_URL=http://localhost:8787/api
# Optional: who users contact for Instagram tester access and scheduling problems
+# Optional: Google web client ID; shows Continue with Google (see /docs/self-host/google-sign-in)
+VITE_GOOGLE_CLIENT_ID=1234567890-abc.apps.googleusercontent.com
```
### Production (Cloudflare Workers secrets)
diff --git a/docs/architecture/cloudflare/CI_CD.md b/docs/architecture/cloudflare/CI_CD.md
index c77c64d..9232a72 100644
--- a/docs/architecture/cloudflare/CI_CD.md
+++ b/docs/architecture/cloudflare/CI_CD.md
@@ -35,6 +35,7 @@
- `VITE_SUPABASE_ANON_KEY` - injected at build time
- `VITE_API_URL` - injected at build time (the Worker URL)
- `VITE_ADMIN_EMAIL` - optional, injected at build time; the administrator contact shown in the app
+- `VITE_GOOGLE_CLIENT_ID` - optional, injected at build time; enables the Sign in with Google button
**Note:** `VITE_*` variables are baked into the built JS bundle at build time. They are not runtime environment variables.
diff --git a/docs/architecture/cloudflare/PAGES.md b/docs/architecture/cloudflare/PAGES.md
index 5ae06c9..e0f4ab7 100644
--- a/docs/architecture/cloudflare/PAGES.md
+++ b/docs/architecture/cloudflare/PAGES.md
@@ -39,6 +39,7 @@ The frontend accesses environment variables at **build time** via Vite's `VITE_`
| `VITE_SUPABASE_URL` | Supabase project URL (public) | Cloudflare Pages -> Settings -> Environment Variables |
| `VITE_SUPABASE_ANON_KEY` | Supabase anon key (public) | Cloudflare Pages -> Settings -> Environment Variables |
| `VITE_API_URL` | Backend Worker URL | Cloudflare Pages -> Settings -> Environment Variables |
+| `VITE_GOOGLE_CLIENT_ID` | Optional. Google Auth Platform web client ID; shows the Sign in with Google button when set | Cloudflare Pages -> Settings -> Environment Variables, or the GitHub secret of the same name |
| `VITE_ADMIN_EMAIL` | Optional. Administrator address shown for Instagram tester requests and scheduling problems; defaults to [email protected] | Cloudflare Pages -> Settings -> Environment Variables, or the GitHub secret of the same name |
**These are public values** - they are baked into the JavaScript bundle. Do not add the service role key here. Do not add any private API credentials here.
diff --git a/docs/architecture/data-flows/AUTHENTICATION.md b/docs/architecture/data-flows/AUTHENTICATION.md
index 8ebd83e..4d54468 100644
--- a/docs/architecture/data-flows/AUTHENTICATION.md
+++ b/docs/architecture/data-flows/AUTHENTICATION.md
@@ -31,6 +31,25 @@ AppProvider mounts -> loadAccounts() fires
User sees Overview dashboard
```
+## Sign in with Google
+
+Optional; enabled when `VITE_GOOGLE_CLIENT_ID` is set and the Google provider is on in Supabase.
+
+```
+Login.jsx renders GoogleSignInButton
+ -> lib/googleIdentity.js loads https://accounts.google.com/gsi/client once
+ -> createNonce(): raw random nonce + its SHA-256 hex
+ -> google.accounts.id.initialize({ client_id, nonce: hashed, callback })
+ -> google.accounts.id.renderButton(...) (Google's own button, popup or FedCM)
+User picks a Google account
+ -> callback receives an ID token (JWT signed by Google, contains the hashed nonce)
+ -> supabase.auth.signInWithIdToken({ provider: 'google', token, nonce: raw })
+ -> Supabase checks the signature, audience (client ID) and sha256(raw) == token nonce
+ -> session issued; same lifecycle as password sign-in below
+```
+
+No OAuth redirect is involved, so the Google client has JavaScript origins only and no redirect URI on `supabase.co`. Every domain Google sees is the frontend's own domain, which is what allows brand verification (name and logo on the consent screen). A Google sign-in with the same verified email as an existing password account opens that account.
+
## Session Lifecycle
```
diff --git a/docs/architecture/frontend/CONTEXTS.md b/docs/architecture/frontend/CONTEXTS.md
index 3b7b71b..1725971 100644
--- a/docs/architecture/frontend/CONTEXTS.md
+++ b/docs/architecture/frontend/CONTEXTS.md
@@ -7,7 +7,7 @@ Wraps Supabase Auth state and exposes it to the entire app.
### What it provides
```js
-const { session, user, signIn, signUp, signOut } = useAuth();
+const { session, user, signIn, signUp, signInWithGoogle, signOut } = useAuth();
```
| Value | Type | Description |
@@ -16,6 +16,7 @@ const { session, user, signIn, signUp, signOut } = useAuth();
| `user` | `User \| null` | `session.user` shorthand |
| `signIn(email, password)` | async function | Calls `supabase.auth.signInWithPassword()` |
| `signUp(email, password)` | async function | Calls `supabase.auth.signUp()` |
+| `signInWithGoogle(idToken, nonce)` | async function | Calls `supabase.auth.signInWithIdToken({ provider: 'google', token, nonce })` with the ID token from Google's button and the raw nonce |
| `signOut()` | async function | Calls `supabase.auth.signOut()` |
### How it works
@@ -37,7 +38,7 @@ useEffect(() => {
### Where to use it
- `ProtectedRoute` - reads `session` to decide whether to redirect to `/login`
-- `Login.jsx` - calls `signIn()` and `signUp()`
+- `Login.jsx` - calls `signIn()`, `signUp()` and `signInWithGoogle()`
- `Header.jsx` - calls `signOut()`, shows `user.email`
- Do **not** use in page/feature components - they should never need auth state directly
diff --git a/docs/workflows/DEPLOYMENT.md b/docs/workflows/DEPLOYMENT.md
index df3de43..539b8a5 100644
--- a/docs/workflows/DEPLOYMENT.md
+++ b/docs/workflows/DEPLOYMENT.md
@@ -69,6 +69,7 @@ Required for `deploy-frontend.yml` and `publish-scheduled.yml`:
- `VITE_SUPABASE_ANON_KEY`
- `VITE_API_URL`
- `VITE_ADMIN_EMAIL` (optional; the administrator contact shown in the app)
+- `VITE_GOOGLE_CLIENT_ID` (optional; Google web client ID for the Sign in with Google button)
**For backend deploy:**
- `CLOUDFLARE_API_TOKEN`
diff --git a/frontend/src/docs/nav.js b/frontend/src/docs/nav.js
index 1d19138..9adc5fa 100644
--- a/frontend/src/docs/nav.js
+++ b/frontend/src/docs/nav.js
@@ -55,6 +55,7 @@ export const DOC_TABS = [
label: 'Set up services',
pages: [
{ slug: 'self-host/supabase', title: 'Supabase', keywords: ['database', 'auth', 'sql', 'rls', 'keys'] },
+ { slug: 'self-host/google-sign-in', title: 'Sign in with Google (optional)', keywords: ['google', 'oauth', 'login', 'branding', 'logo', 'verification'] },
{ slug: 'self-host/youtube', title: 'YouTube API key', keywords: ['google cloud', 'data api'] },
{ slug: 'self-host/instagram', title: 'Instagram app', keywords: ['meta', 'facebook', 'oauth', 'redirect', 'tester', 'app review'] },
{ slug: 'self-host/cloudinary', title: 'Cloudinary', keywords: ['media', 'upload preset', 'cdn'] },
diff --git a/frontend/src/docs/pages/Reference.jsx b/frontend/src/docs/pages/Reference.jsx
index decea0c..78b46ef 100644
--- a/frontend/src/docs/pages/Reference.jsx
+++ b/frontend/src/docs/pages/Reference.jsx
@@ -21,6 +21,7 @@ const FRONTEND_VARS = [
['VITE_SUPABASE_ANON_KEY', 'required', 'The publishable key. Never the secret key.'],
['VITE_API_URL', 'required', 'Backend URL plus /api, for example https://twiligent.you.workers.dev/api. Defaults to http://localhost:8787/api in development.'],
['VITE_ADMIN_EMAIL', 'optional', 'Where members are told to write for Instagram tester access or help.'],
+ ['VITE_GOOGLE_CLIENT_ID', 'optional', 'Web client ID from Google Auth Platform. Shows the Sign in with Google button; leave unset to hide it.'],
];
const NEED = {
@@ -66,7 +67,7 @@ export function Environment() {
rows={[
[<Code>CLOUDFLARE_API_TOKEN</Code>, 'Both deploy workflows'],
[<Code>CLOUDFLARE_ACCOUNT_ID</Code>, 'Both deploy workflows'],
- [<><Code>VITE_SUPABASE_URL</Code>, <Code>VITE_SUPABASE_ANON_KEY</Code>, <Code>VITE_API_URL</Code>, <Code>VITE_ADMIN_EMAIL</Code></>, 'Frontend deploy workflow'],
+ [<><Code>VITE_SUPABASE_URL</Code>, <Code>VITE_SUPABASE_ANON_KEY</Code>, <Code>VITE_API_URL</Code>, <Code>VITE_ADMIN_EMAIL</Code>, <Code>VITE_GOOGLE_CLIENT_ID</Code></>, 'Frontend deploy workflow'],
[<><Code>SUPABASE_URL</Code>, <Code>SUPABASE_SERVICE_KEY</Code></>, 'Backup scheduler (publish-scheduled.yml)'],
]}
/>
diff --git a/frontend/src/docs/pages/SelfHost.jsx b/frontend/src/docs/pages/SelfHost.jsx
index 384a2af..dc8e6a6 100644
--- a/frontend/src/docs/pages/SelfHost.jsx
+++ b/frontend/src/docs/pages/SelfHost.jsx
@@ -151,6 +151,42 @@ ${RLS_SQL.trim()}
);
}
+export function GoogleSignIn() {
+ return (
+ <>
+ <DocTitle title="Sign in with Google (optional)" lead="Let members sign in with their Google account, with your name and logo on Google's sign-in screen." />
+
+ <Callout type="note" title="How it works">
+ <p>Twiligent shows Google's own sign-in button. Google returns a signed ID token to the browser, and Supabase verifies it directly. Nothing redirects through your Supabase address, so every domain Google sees is one you own, which is what lets Google approve your logo.</p>
+ </Callout>
+
+ <Steps>
+ <Step title="Serve Twiligent from your own domain">
+ <P>Google only verifies domains you prove you own in <A href="https://search.google.com/search-console">Search Console</A>. Addresses like <Code>twiligent.pages.dev</Code> cannot be verified, so add a custom domain such as <Code>twiligent.example.com</Code> to your Cloudflare Pages project under <strong>Custom domains</strong>, and update <Code>FRONTEND_URL</Code> on the Worker.</P>
+ </Step>
+ <Step title="Set up branding">
+ <P>In <A href="https://console.cloud.google.com/auth/branding">Google Auth Platform, Branding</A>, enter the app name, support email and a 120 by 120 pixel logo. Set the home page and privacy policy links; both must be on your domain, and the home page must link to the privacy policy. Add your domain under <strong>Authorized domains</strong>. One entry covers all its subdomains.</P>
+ </Step>
+ <Step title="Choose the audience and scopes">
+ <P>Under <strong>Audience</strong>, pick <strong>External</strong> and publish the app to production. Under <strong>Data access</strong>, add only <Code>openid</Code>, <Code>userinfo.email</Code> and <Code>userinfo.profile</Code>. These are not sensitive, so there is no user cap and no security review.</P>
+ </Step>
+ <Step title="Create the client">
+ <P>Under <strong>Clients</strong>, create a <strong>Web application</strong>. Add your Twiligent address as an authorized JavaScript origin, plus <Code>http://localhost:5173</Code> for development. No redirect URI is needed. Copy the client ID.</P>
+ </Step>
+ <Step title="Turn on Google in Supabase">
+ <P>In Supabase, open <strong>Authentication</strong>, <strong>Sign In / Providers</strong>, <strong>Google</strong>. Enable it and paste the client ID into <strong>Client IDs</strong>. Leave <strong>Skip nonce checks</strong> off; Twiligent sends a nonce with every sign-in.</P>
+ </Step>
+ <Step title="Add the client ID to the frontend">
+ <P>Set <Code>VITE_GOOGLE_CLIENT_ID</Code> in <Code>frontend/.env</Code> and as a GitHub secret, then redeploy. The <strong>Continue with Google</strong> button appears on the sign-in page.</P>
+ </Step>
+ <Step title="Submit for brand verification">
+ <P>Open <strong>Verification Center</strong> and submit. Google reviews brands with basic scopes in a few business days. Until then sign-in works, but Google shows your domain instead of your name and logo.</P>
+ </Step>
+ </Steps>
+ </>
+ );
+}
+
export function YouTube() {
return (
<>
diff --git a/frontend/src/docs/pages/Use.jsx b/frontend/src/docs/pages/Use.jsx
index e67bb7b..133af7e 100644
--- a/frontend/src/docs/pages/Use.jsx
+++ b/frontend/src/docs/pages/Use.jsx
@@ -17,7 +17,7 @@ export function GettingStarted() {
<Steps>
<Step title="Create your account">
- <P>Open your instance's link and choose <strong>Create an account</strong>. Use your email and a password of at least 6 characters, then sign in.</P>
+ <P>Open your instance's link and choose <strong>Continue with Google</strong>, if your instance offers it. Otherwise choose <strong>Create an account</strong> and use your email and a password of at least 6 characters, then sign in. If you sign in with Google using the same email as an existing account, both open the same account.</P>
</Step>
<Step title="Connect an account">
<P>Open <strong>Accounts</strong> in the sidebar and choose <strong>Add account</strong>. Pick YouTube, Instagram or Reddit. Each one is explained in <A to="/docs/use/connect-accounts">Connect your accounts</A>.</P>
diff --git a/frontend/src/docs/routes.js b/frontend/src/docs/routes.js
index db44e7a..d933a55 100644
--- a/frontend/src/docs/routes.js
+++ b/frontend/src/docs/routes.js
@@ -24,6 +24,7 @@ const PAGES = {
'use/troubleshooting': page('use', 'Troubleshooting'),
'self-host': page('selfHost', 'Overview'),
'self-host/supabase': page('selfHost', 'Supabase'),
+ 'self-host/google-sign-in': page('selfHost', 'GoogleSignIn'),
'self-host/youtube': page('selfHost', 'YouTube'),
'self-host/instagram': page('selfHost', 'Instagram'),
'self-host/cloudinary': page('selfHost', 'Cloudinary'),