Files
token-circles/worker/migrations/0022_email_verifications.sql
KomediruzeckiandGitHub 8a18f3c9a2 feat(auth): confirm the email address a password signup was given (#415)
users.email_verified has been in the schema since 0001_init.sql, written and
never asked for. Register inserted 0; the only things that set 1 were Google's
own claim and completing a password reset. Nothing read it — login did not check
it and /api/auth/me did not return it — so an address nobody had ever confirmed
was indistinguishable from one that had.

That matters most in the place it is least visible: password reset. The reset
link goes to whatever address was typed at signup, so a typo hands the only way
back into the account to whoever owns the address that was actually typed.

The confirm link now rides in the welcome mail, and a strip at the top of the app
offers to send it again until it is clicked. Soft gate: the account works
unverified, which is the shape mercurypitch settled on. Google accounts arrive
confirmed by Google and see none of it.

The token lifecycle is the one password_resets already uses — only the SHA-256
stored, single-use, superseded on resend, expiry at use time — with a longer TTL,
because a reset link is a live credential and a confirm link is not. The row also
keeps the address it was minted for: without that, changing the address after
asking for a link confirms the NEW one on the strength of mail sent to the old.

Worker only. The legacy Express backend has no register route and browser-only
mode has no accounts. The banner shows nothing when /me omits the field, which is
how the legacy server answers — reading that absence as "unverified" would nag
every one of its users with a button its API cannot answer.
2026-08-23 21:18:55 +02:00

21 lines
1018 B
SQL

-- Email verification (migration 0022). Confirm-your-address links for password signups.
--
-- Same shape and the same reasoning as password_resets (0005): only a SHA-256 hash of the
-- token is stored, so a database leak yields no usable confirm links — the raw token exists
-- only inside the email.
--
-- `email` is kept alongside the user id on purpose. A token is minted for one address; if the
-- account's address changes before the link is clicked, confirming would otherwise mark the
-- NEW address verified on the strength of an email sent to the old one.
CREATE TABLE IF NOT EXISTS email_verifications (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
email TEXT NOT NULL,
token_hash TEXT NOT NULL,
expires_at TEXT NOT NULL,
used_at TEXT,
created_at TEXT NOT NULL DEFAULT (datetime('now'))
);
CREATE INDEX IF NOT EXISTS idx_email_verifications_token ON email_verifications(token_hash);
CREATE INDEX IF NOT EXISTS idx_email_verifications_user ON email_verifications(user_id);