Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
Blame · Line-by-line history

0051_magic_link_tokens.sql

Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.

0051_magic_link_tokens.sqlBlame40 lines · 1 contributor
cd4f63bTest User1-- Block Q2 — Magic-link sign-in tokens.
2--
3-- One row per outstanding magic-link sign-in request. Mirrors the structure
4-- of 0047_password_reset_tokens.sql and 0048_email_verification.sql — short
5-- random plaintext mailed to the user, sha256 hash persisted, single-use,
6-- time-limited (15-minute TTL enforced at consume time).
7--
8-- `user_id` is NULLABLE: when a user enters an email that does NOT yet have
9-- an account, we still mint a token so consume can create the account on
10-- click (autoCreate=true). The link click is the proof the email is owned.
11--
12-- Strictly additive — drop this table to remove the feature. No changes to
13-- `users` are required; account auto-create happens via `users` INSERT in
14-- `src/lib/magic-link.ts::consumeMagicLinkToken`.
15
16CREATE TABLE IF NOT EXISTS "magic_link_tokens" (
17 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
18 "email" text NOT NULL,
19 "user_id" uuid REFERENCES "users"("id") ON DELETE CASCADE,
20 "token_hash" text NOT NULL UNIQUE,
21 "expires_at" timestamptz NOT NULL,
22 "used_at" timestamptz,
23 "request_ip" text,
24 "created_at" timestamptz NOT NULL DEFAULT now()
25);
26
27--> statement-breakpoint
28
29CREATE INDEX IF NOT EXISTS "idx_magic_link_tokens_email"
30 ON "magic_link_tokens" ("email");
31
32--> statement-breakpoint
33
34CREATE INDEX IF NOT EXISTS "idx_magic_link_tokens_user"
35 ON "magic_link_tokens" ("user_id");
36
37--> statement-breakpoint
38
39CREATE INDEX IF NOT EXISTS "idx_magic_link_tokens_expires"
40 ON "magic_link_tokens" ("expires_at");