create-disposabl-app 0.17.5 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/README.md +4 -0
  2. package/dist/disposabl.js +43 -10
  3. package/dist/index.js +64 -18
  4. package/dist/templates/default/apps/mobile/README.md +40 -0
  5. package/dist/templates/default/apps/mobile/app.config.js +46 -2
  6. package/dist/templates/default/apps/mobile/package.json +7 -1
  7. package/dist/templates/default/apps/mobile/plugins/with-android-signing.js +23 -1
  8. package/dist/templates/default/apps/mobile/scripts/fresh-android.mjs +24 -0
  9. package/dist/templates/default/apps/mobile/scripts/play-aab.mjs +176 -0
  10. package/dist/templates/default/apps/mobile/scripts/verify-play-aab.mjs +77 -0
  11. package/dist/templates/default/bun.lock +12 -3
  12. package/dist/templates/default/bunfig.toml +1 -0
  13. package/dist/templates/default/package.json +6 -2
  14. package/dist/templates/default/packages/backend/convex/files/guard.ts +2 -0
  15. package/dist/templates/default/packages/backend/convex/http.ts +11 -1
  16. package/dist/templates/default/packages/backend/convex/schema.ts +10 -0
  17. package/dist/templates/default/packages/backend/convex/telemetry.ts +12 -16
  18. package/dist/templates/default/packages/cli/build.ts +4 -0
  19. package/dist/templates/default/packages/cli/package.json +2 -1
  20. package/dist/templates/default/packages/cli/telemetry.ts +40 -3
  21. package/dist/templates/default/packages/disposabl-kit/PAYMENTS.md +2 -0
  22. package/dist/templates/default/packages/disposabl-kit/client/components/account-deletion.tsx +111 -0
  23. package/dist/templates/default/packages/disposabl-kit/client/components/consent-identity.tsx +50 -0
  24. package/dist/templates/default/packages/disposabl-kit/client/components/legal-page.tsx +12 -1
  25. package/dist/templates/default/packages/disposabl-kit/client/lib/telemetry-lease.ts +200 -0
  26. package/dist/templates/default/packages/disposabl-kit/client/lib/telemetry.ts +8 -1
  27. package/dist/templates/default/packages/disposabl-kit/client/routes/consent.tsx +23 -1
  28. package/dist/templates/default/packages/disposabl-kit/client/routes/legal/delete-account.tsx +6 -1
  29. package/dist/templates/default/packages/disposabl-kit/client/routes/legal/support.tsx +33 -0
  30. package/dist/templates/default/packages/disposabl-kit/client/routes/pricing.tsx +13 -0
  31. package/dist/templates/default/packages/disposabl-kit/client/routes/route.tsx +19 -2
  32. package/dist/templates/default/packages/disposabl-kit/client/vite.config.ts +1 -0
  33. package/dist/templates/default/packages/disposabl-kit/legal/README.md +1 -1
  34. package/dist/templates/default/packages/disposabl-kit/legal/config.ts +32 -4
  35. package/dist/templates/default/packages/disposabl-kit/legal/index.ts +2 -2
  36. package/dist/templates/default/packages/disposabl-kit/legal/publisher.ts +6 -0
  37. package/dist/templates/default/packages/disposabl-kit/mobile/billing/account-billing.tsx +13 -9
  38. package/dist/templates/default/packages/disposabl-kit/mobile/billing/paywall.ts +28 -4
  39. package/dist/templates/default/packages/disposabl-kit/mobile/billing/policy.ts +31 -14
  40. package/dist/templates/default/packages/disposabl-kit/mobile/billing/web-checkout.ts +45 -34
  41. package/dist/templates/default/packages/disposabl-kit/mobile/components/settings-links.tsx +14 -0
  42. package/dist/templates/default/packages/disposabl-kit/mobile/expo-plugin.cjs +3 -0
  43. package/dist/templates/default/packages/disposabl-kit/mobile/index.ts +4 -0
  44. package/dist/templates/default/packages/disposabl-kit/mobile/layout.tsx +55 -8
  45. package/dist/templates/default/packages/disposabl-kit/server/billing-functions.ts +147 -124
  46. package/dist/templates/default/packages/disposabl-kit/server/billing-handoff.ts +113 -95
  47. package/dist/templates/default/packages/disposabl-kit/server/files-functions.ts +70 -54
  48. package/dist/templates/default/packages/disposabl-kit/server/http.ts +49 -21
  49. package/dist/templates/default/packages/disposabl-kit/server/lib/platform-spec.ts +25 -1
  50. package/dist/templates/default/packages/disposabl-kit/server/lib/telemetry.ts +375 -69
  51. package/dist/templates/default/packages/disposabl-kit/server/release/clients.mjs +28 -1
  52. package/dist/templates/default/packages/disposabl-kit/server/release/verify-metadata.mjs +64 -0
  53. package/dist/templates/default/packages/sdk/README.md +2 -0
  54. package/dist/templates/default/packages/sdk/build.ts +8 -0
  55. package/dist/templates/default/packages/sdk/package.json +3 -2
  56. package/dist/templates/default/packages/sdk/src/analytics.ts +7 -2
  57. package/dist/templates/default/packages/skill/SKILL.md +4 -2
  58. package/dist/templates/default/packages/skill/references/store-submissions.md +25 -0
  59. package/dist/templates/default/packages/tests/README.md +28 -1
  60. package/dist/templates/default/packages/tests/account-deletion-ui.test.ts +21 -0
  61. package/dist/templates/default/packages/tests/auth-email-setup.test.ts +45 -0
  62. package/dist/templates/default/packages/tests/components/account-deletion.test.mjs +82 -0
  63. package/dist/templates/default/packages/tests/components/consent-identity.test.mjs +175 -0
  64. package/dist/templates/default/packages/tests/components/mobile-deletion-link.test.mjs +40 -0
  65. package/dist/templates/default/packages/tests/components/mobile-theme.test.mjs +56 -3
  66. package/dist/templates/default/packages/tests/components/pricing-identity.test.mjs +113 -0
  67. package/dist/templates/default/packages/tests/components/support-page.test.mjs +36 -0
  68. package/dist/templates/default/packages/tests/consent-identity.test.ts +13 -0
  69. package/dist/templates/default/packages/tests/desktop-macos-release.test.ts +153 -145
  70. package/dist/templates/default/packages/tests/flows/legal.e2e.ts +40 -3
  71. package/dist/templates/default/packages/tests/helpers/auth-email-setup/probe.test.mjs +44 -0
  72. package/dist/templates/default/packages/tests/helpers/mobile-simulator/preflight.py +80 -0
  73. package/dist/templates/default/packages/tests/helpers/mobile-simulator/test_preflight.py +57 -0
  74. package/dist/templates/default/packages/tests/mobile-android-e2e-network.test.ts +81 -1
  75. package/dist/templates/default/packages/tests/mobile-android-signing.test.ts +52 -0
  76. package/dist/templates/default/packages/tests/mobile-deletion-link.test.ts +21 -0
  77. package/dist/templates/default/packages/tests/mobile-ios-reachability-pin.test.ts +84 -0
  78. package/dist/templates/default/packages/tests/mobile-simulator-preflight.test.ts +16 -0
  79. package/dist/templates/default/packages/tests/native-billing.test.ts +288 -0
  80. package/dist/templates/default/packages/tests/pricing-identity.test.ts +13 -0
  81. package/dist/templates/default/packages/tests/sdk-analytics.test.ts +28 -2
  82. package/dist/templates/default/packages/tests/support-page.test.ts +13 -0
  83. package/dist/templates/default/packages/tests/telemetry.test.ts +389 -18
  84. package/dist/templates/default/packages/tests/ui-telemetry-lease.test.ts +346 -0
  85. package/dist/templates/default/patches/convex-mcp-account-erasure-alpha7.patch +466 -0
  86. package/dist/templates/default/vendor/README.md +61 -1
  87. package/dist/templates/default/vendor/convex-auth-040d8e36-disposabl.1.patch +890 -0
  88. package/dist/templates/default/vendor/convex-auth-040d8e36-disposabl.1.tgz +0 -0
  89. package/dist/templates/default/vendor/convex-auth-040d8e36-disposabl.2.patch +1060 -0
  90. package/dist/templates/default/vendor/convex-auth-040d8e36-disposabl.2.tgz +0 -0
  91. package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.4.tgz +0 -0
  92. package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.5.tgz +0 -0
  93. package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.6.tgz +0 -0
  94. package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.7.tgz +0 -0
  95. package/dist/templates/default/vendor/convex-auth-437831bd-disposabl.8.tgz +0 -0
  96. package/dist/templates/default/vendor/convex-auth-core-erasure-disposabl.6.patch +115 -0
  97. package/dist/templates/default/vendor/convex-auth-identity-cutoff-disposabl.7.patch +442 -0
  98. package/dist/templates/default/vendor/convex-auth-identity-erasure-disposabl.8.md +11 -0
  99. package/dist/templates/default/vendor/convex-auth-identity-erasure-disposabl.8.patch +78 -0
  100. package/dist/templates/default/vendor/convex-auth-marker-disposabl.4.patch +169 -0
  101. package/dist/templates/default/vendor/convex-auth-marker-password-disposabl.5.patch +126 -0
  102. package/dist/verify-metadata.mjs +64 -0
  103. package/package.json +3 -2
@@ -0,0 +1,890 @@
1
+ --- a/src/browser/sessionManager.ts
2
+ +++ b/src/browser/sessionManager.ts
3
+ @@ -410,7 +410,7 @@
4
+ setSession = async (
5
+ session: TokenBundle | SlimTokenBundle,
6
+ ): Promise<void> => {
7
+ - await this.#storeFullTokenResult(session);
8
+ + await runWithMutex(this.#lockKey, () => this.#storeFullTokenResult(session));
9
+ };
10
+
11
+ /**
12
+ --- a/src/component/_generated/component.ts
13
+ +++ b/src/component/_generated/component.ts
14
+ @@ -24,6 +24,52 @@
15
+ export type ComponentApi<Name extends string | undefined = string | undefined> =
16
+ {
17
+ public: {
18
+ + getIdentityErasureCutoff: FunctionReference<
19
+ + "query",
20
+ + "internal",
21
+ + { provider: string; providerAccountId: string },
22
+ + number | null,
23
+ + Name
24
+ + >;
25
+ + beginUserErasure: FunctionReference<
26
+ + "mutation",
27
+ + "internal",
28
+ + { userId: string },
29
+ + null,
30
+ + Name
31
+ + >;
32
+ + purgeUserLinkedAuth: FunctionReference<
33
+ + "mutation",
34
+ + "internal",
35
+ + { userId: string },
36
+ + {
37
+ + linkedRowsCleared: boolean;
38
+ + deletedAccounts: number;
39
+ + deletedSessions: number;
40
+ + deletedRefreshTokens: number;
41
+ + legacyOrphansUnverified: true;
42
+ + },
43
+ + Name
44
+ + >;
45
+ + exchangeSession: FunctionReference<
46
+ + "mutation",
47
+ + "internal",
48
+ + {
49
+ + sessionId: string;
50
+ + userId: string;
51
+ + accessTokenTtlSeconds: number;
52
+ + refreshInactivityTimeoutSeconds: number;
53
+ + sessionMaxLifetimeSeconds: number;
54
+ + },
55
+ + {
56
+ + accessToken: string;
57
+ + refreshToken: string;
58
+ + refreshTokenExpiresAt: number;
59
+ + userId: string;
60
+ + },
61
+ + Name
62
+ + >;
63
+ +
64
+ getSession: FunctionReference<
65
+ "query",
66
+ "internal",
67
+ --- a/src/component/public.ts
68
+ +++ b/src/component/public.ts
69
+ @@ -49,6 +49,35 @@
70
+
71
+ // --- Internal helpers ------------------------------------------------------
72
+
73
+ +async function erasedUser(ctx: QueryCtx, userId: string) {
74
+ + return await ctx.db
75
+ + .query("erasedUsers")
76
+ + .withIndex("by_userId", (q) => q.eq("userId", userId))
77
+ + .unique();
78
+ +}
79
+ +// Pseudonymous, stable and potentially guessable; retention policy is required.
80
+ +async function identityDigest(provider: string, account: string) {
81
+ + return sha256Hex(JSON.stringify([provider, account]));
82
+ +}
83
+ +async function identityCutoff(
84
+ + ctx: QueryCtx,
85
+ + provider: string,
86
+ + account: string,
87
+ +): Promise<number | null> {
88
+ + const digest = await identityDigest(provider, account);
89
+ + const tombstone = await ctx.db
90
+ + .query("identityErasure")
91
+ + .withIndex("by_digest", (q) => q.eq("digest", digest))
92
+ + .unique();
93
+ + const mapped = await accountByIdentity(ctx, provider, account);
94
+ + const user = mapped ? await erasedUser(ctx, mapped.userId) : null;
95
+ + return Math.max(tombstone?.cutoff ?? 0, user?.requestedAt ?? 0) || null;
96
+ +}
97
+ +async function requireActiveUser(ctx: QueryCtx, userId: string) {
98
+ + if (await erasedUser(ctx, userId))
99
+ + throw new Error("Auth account is unavailable.");
100
+ +}
101
+ +
102
+ /** Look up an account by its provider identity. */
103
+ function accountByIdentity(
104
+ ctx: QueryCtx,
105
+ @@ -89,6 +118,7 @@
106
+ userId: string,
107
+ ttl: TtlConfig,
108
+ ): Promise<TokenBundle> {
109
+ + await requireActiveUser(ctx, userId);
110
+ const now = Date.now();
111
+ await evictLeastRecentlyRefreshedSessions(ctx, userId);
112
+ const sessionId = await ctx.db.insert("sessions", {
113
+ @@ -166,6 +196,10 @@
114
+ // identifier), so there is nothing to check yet; the pre-insert check below
115
+ // covers that path once the key is known.
116
+ if (claims.providerAccountId !== USE_USER_ID_AS_ACCOUNT_ID) {
117
+ + if (
118
+ + await identityCutoff(ctx, claims.providerName, claims.providerAccountId)
119
+ + )
120
+ + throw new Error("Identity registration is unavailable.");
121
+ const account = await accountByIdentity(
122
+ ctx,
123
+ claims.providerName,
124
+ @@ -191,11 +225,14 @@
125
+ profile: claims.profile,
126
+ },
127
+ });
128
+ + await requireActiveUser(ctx, userId);
129
+ const { providerName } = claims;
130
+ const providerAccountId =
131
+ claims.providerAccountId === USE_USER_ID_AS_ACCOUNT_ID
132
+ ? userId
133
+ : claims.providerAccountId;
134
+ + if (await identityCutoff(ctx, providerName, providerAccountId))
135
+ + throw new Error("Identity registration is unavailable.");
136
+ // The last word on uniqueness, for the `USE_USER_ID_AS_ACCOUNT_ID` path,
137
+ // whose key is only known now. Redundant for every other path, and cheap.
138
+ const existingAccount = await ctx.db
139
+ @@ -318,6 +355,7 @@
140
+ `A first sign-in for an identity must go through signUp.`,
141
+ );
142
+ }
143
+ + await requireActiveUser(ctx, account.userId);
144
+ await notifySignIn(ctx, claims, account.userId, args.onSignInHandle);
145
+ return await issueSession(ctx, account._id, account.userId, ttl);
146
+ },
147
+ @@ -396,7 +434,9 @@
148
+ const id = ctx.db.normalizeId("sessions", sessionId);
149
+ if (id === null) return null;
150
+ const session = await ctx.db.get("sessions", id);
151
+ - return session === null ? null : { userId: session.userId };
152
+ + return session === null || (await erasedUser(ctx, session.userId))
153
+ + ? null
154
+ + : { userId: session.userId };
155
+ },
156
+ });
157
+
158
+ @@ -454,7 +494,8 @@
159
+ // `deleteSession`), so a token can outlive its session for a moment. The
160
+ // session ended already, thus there is nothing to refresh or revoke.
161
+ const session = await ctx.db.get("sessions", token.sessionId);
162
+ - if (session === null) return { kind: "noSession" };
163
+ + if (session === null || (await erasedUser(ctx, session.userId)))
164
+ + return { kind: "noSession" };
165
+
166
+ switch (token.state) {
167
+ case "spent":
168
+ @@ -652,3 +693,140 @@
169
+ return revoked;
170
+ },
171
+ });
172
+ +
173
+ +/** App-server-only: exchange a verified live session for a separate device session.
174
+ + * The calling app must authenticate the source or consume a single-use handoff.
175
+ + */
176
+ +export const exchangeSession = mutation({
177
+ + args: { sessionId: v.string(), userId: v.string(), ...vTtlConfigFields },
178
+ + returns: vTokenBundle,
179
+ + handler: async (ctx, args): Promise<TokenBundle> => {
180
+ + const ttl = validateTtlConfig(args);
181
+ + const id = ctx.db.normalizeId("sessions", args.sessionId);
182
+ + const session = id ? await ctx.db.get("sessions", id) : null;
183
+ + if (!session || session.userId !== args.userId)
184
+ + throw new Error("Source session is no longer active.");
185
+ + const latest = await newestIssuedToken(ctx, session._id);
186
+ + const now = Date.now();
187
+ + if (
188
+ + !latest ||
189
+ + refreshTokenInactivityExpiresAt(
190
+ + latest,
191
+ + ttl.refreshInactivityTimeoutSeconds,
192
+ + ) <= now ||
193
+ + sessionMaxLifetimeExpiresAt(session, ttl.sessionMaxLifetimeSeconds) <= now
194
+ + )
195
+ + throw new Error("Source session has expired.");
196
+ + const account = await ctx.db.get("accounts", session.accountId);
197
+ + if (!account || account.userId !== session.userId)
198
+ + throw new Error("Source account is no longer active.");
199
+ + return await issueSession(ctx, session.accountId, session.userId, ttl);
200
+ + },
201
+ +});
202
+ +
203
+ +/** App-server-only fence. Coordinate with provider-component fences in one app mutation. */
204
+ +export const beginUserErasure = mutation({
205
+ + args: { userId: v.string() },
206
+ + returns: v.null(),
207
+ + handler: async (ctx, { userId }) => {
208
+ + if (!userId) throw new Error("Missing user ID.");
209
+ + if (!(await erasedUser(ctx, userId)))
210
+ + await ctx.db.insert("erasedUsers", { userId, requestedAt: Date.now() });
211
+ + return null;
212
+ + },
213
+ +});
214
+ +/** Bounded cleanup of linked records only; older orphan refresh tokens lack a user join. */
215
+ +export const purgeUserLinkedAuth = mutation({
216
+ + args: { userId: v.string() },
217
+ + returns: v.object({
218
+ + linkedRowsCleared: v.boolean(),
219
+ + deletedAccounts: v.number(),
220
+ + deletedSessions: v.number(),
221
+ + deletedRefreshTokens: v.number(),
222
+ + legacyOrphansUnverified: v.literal(true),
223
+ + }),
224
+ + handler: async (ctx, { userId }) => {
225
+ + if (!(await erasedUser(ctx, userId)))
226
+ + throw new Error("Begin auth erasure first.");
227
+ + const receipt = await ctx.db
228
+ + .query("sessionCleanupReceipts")
229
+ + .withIndex("by_user", (q) => q.eq("userId", userId))
230
+ + .first();
231
+ + if (receipt) {
232
+ + const tokens = await ctx.db
233
+ + .query("refreshTokens")
234
+ + .withIndex("by_session_state", (q) =>
235
+ + q.eq("sessionId", receipt.sessionId),
236
+ + )
237
+ + .take(101);
238
+ + for (const token of tokens.slice(0, 100))
239
+ + await ctx.db.delete("refreshTokens", token._id);
240
+ + if (tokens.length <= 100)
241
+ + await ctx.db.delete("sessionCleanupReceipts", receipt._id);
242
+ + return {
243
+ + linkedRowsCleared: false,
244
+ + deletedAccounts: 0,
245
+ + deletedSessions: 0,
246
+ + deletedRefreshTokens: Math.min(tokens.length, 100),
247
+ + legacyOrphansUnverified: true as const,
248
+ + };
249
+ + }
250
+ + const session = await ctx.db
251
+ + .query("sessions")
252
+ + .withIndex("by_user", (q) => q.eq("userId", userId))
253
+ + .first();
254
+ + if (session) {
255
+ + const tokens = await ctx.db
256
+ + .query("refreshTokens")
257
+ + .withIndex("by_session_state", (q) => q.eq("sessionId", session._id))
258
+ + .take(101);
259
+ + for (const token of tokens.slice(0, 100))
260
+ + await ctx.db.delete("refreshTokens", token._id);
261
+ + const deletedSessions = tokens.length <= 100 ? 1 : 0;
262
+ + if (deletedSessions) await ctx.db.delete("sessions", session._id);
263
+ + return {
264
+ + linkedRowsCleared: false,
265
+ + deletedAccounts: 0,
266
+ + deletedSessions,
267
+ + deletedRefreshTokens: Math.min(tokens.length, 100),
268
+ + legacyOrphansUnverified: true as const,
269
+ + };
270
+ + }
271
+ + const accounts = await ctx.db
272
+ + .query("accounts")
273
+ + .withIndex("by_user", (q) => q.eq("userId", userId))
274
+ + .take(101);
275
+ + const cutoff = (await erasedUser(ctx, userId))!.requestedAt;
276
+ + for (const account of accounts.slice(0, 100)) {
277
+ + const digest = await identityDigest(
278
+ + account.provider,
279
+ + account.providerAccountId,
280
+ + );
281
+ + const prior = await ctx.db
282
+ + .query("identityErasure")
283
+ + .withIndex("by_digest", (q) => q.eq("digest", digest))
284
+ + .unique();
285
+ + if (prior)
286
+ + await ctx.db.patch("identityErasure", prior._id, {
287
+ + cutoff: Math.max(prior.cutoff, cutoff),
288
+ + });
289
+ + else await ctx.db.insert("identityErasure", { digest, cutoff });
290
+ + await ctx.db.delete("accounts", account._id);
291
+ + }
292
+ + return {
293
+ + linkedRowsCleared: accounts.length <= 100,
294
+ + deletedAccounts: Math.min(accounts.length, 100),
295
+ + deletedSessions: 0,
296
+ + deletedRefreshTokens: 0,
297
+ + legacyOrphansUnverified: true as const,
298
+ + };
299
+ + },
300
+ +});
301
+ +
302
+ +/** App-server query: returns a cutoff while a mapped owner is fenced and after mapping purge. */
303
+ +export const getIdentityErasureCutoff = query({
304
+ + args: { provider: v.string(), providerAccountId: v.string() },
305
+ + returns: v.union(v.number(), v.null()),
306
+ + handler: (ctx, { provider, providerAccountId }) =>
307
+ + identityCutoff(ctx, provider, providerAccountId),
308
+ +});
309
+ --- a/src/component/schema.ts
310
+ +++ b/src/component/schema.ts
311
+ @@ -2,6 +2,20 @@
312
+ import { v } from "convex/values";
313
+
314
+ export default defineSchema({
315
+ + erasedUsers: defineTable({
316
+ + userId: v.string(),
317
+ + requestedAt: v.number(),
318
+ + }).index("by_userId", ["userId"]),
319
+ + identityErasure: defineTable({
320
+ + digest: v.string(),
321
+ + cutoff: v.number(),
322
+ + }).index("by_digest", ["digest"]),
323
+ + sessionCleanupReceipts: defineTable({
324
+ + userId: v.string(),
325
+ + sessionId: v.id("sessions"),
326
+ + })
327
+ + .index("by_user", ["userId"])
328
+ + .index("by_session", ["sessionId"]),
329
+ // Maps a provider-scoped identity to an opaque app user id. The app owns the
330
+ // actual users table; we only store the id string it gives us back.
331
+ accounts: defineTable({
332
+ --- a/src/component/sessions.ts
333
+ +++ b/src/component/sessions.ts
334
+ @@ -146,9 +146,17 @@
335
+ ): Promise<void> {
336
+ // `delete` throws on an id that is already gone, and the session may have
337
+ // been deleted by whoever we raced, which also scheduled its tokens.
338
+ - if ((await ctx.db.get("sessions", sessionId)) === null) {
339
+ - return;
340
+ - }
341
+ + const session = await ctx.db.get("sessions", sessionId);
342
+ + if (session === null) return;
343
+ + const receipt = await ctx.db
344
+ + .query("sessionCleanupReceipts")
345
+ + .withIndex("by_session", (q) => q.eq("sessionId", sessionId))
346
+ + .unique();
347
+ + if (!receipt)
348
+ + await ctx.db.insert("sessionCleanupReceipts", {
349
+ + userId: session.userId,
350
+ + sessionId,
351
+ + });
352
+ await ctx.db.delete("sessions", sessionId);
353
+ await ctx.scheduler.runAfter(0, internal.sessions.deleteSessionTokens, {
354
+ sessionId,
355
+ @@ -175,6 +183,13 @@
356
+ .take(TOKEN_DELETION_BATCH_SIZE);
357
+ for (const row of tokens) {
358
+ await ctx.db.delete("refreshTokens", row._id);
359
+ + }
360
+ + if (tokens.length < TOKEN_DELETION_BATCH_SIZE) {
361
+ + const receipt = await ctx.db
362
+ + .query("sessionCleanupReceipts")
363
+ + .withIndex("by_session", (q) => q.eq("sessionId", sessionId))
364
+ + .unique();
365
+ + if (receipt) await ctx.db.delete("sessionCleanupReceipts", receipt._id);
366
+ }
367
+ if (tokens.length === TOKEN_DELETION_BATCH_SIZE) {
368
+ await ctx.scheduler.runAfter(0, internal.sessions.deleteSessionTokens, {
369
+ --- a/src/components/apple/_generated/component.ts
370
+ +++ b/src/components/apple/_generated/component.ts
371
+ @@ -28,7 +28,7 @@
372
+ "mutation",
373
+ "internal",
374
+ { stateHash: string; ticketCodeHash: string },
375
+ - null | { encryptedPayload: string },
376
+ + null | { encryptedPayload: string; authorizationStartedAt?: number },
377
+ Name
378
+ >;
379
+ createAuthorizationRequest: FunctionReference<
380
+ --- a/src/components/email/_generated/component.ts
381
+ +++ b/src/components/email/_generated/component.ts
382
+ @@ -267,6 +267,7 @@
383
+ };
384
+ };
385
+ verifiedEmails: {
386
+ + eraseUserBatch: FunctionReference<"mutation", "internal", { userId: string }, { emailsDeleted: number; challengesDeleted: number; complete: boolean }, Name>;
387
+ deleteUser: FunctionReference<
388
+ "mutation",
389
+ "internal",
390
+ --- a/src/components/email/challenge/common.ts
391
+ +++ b/src/components/email/challenge/common.ts
392
+ @@ -392,6 +392,9 @@
393
+ copy: ChallengeEmailCopy;
394
+ },
395
+ ): Promise<{ browserSecret: string; challengeId: Id<"challenges"> }> {
396
+ + const challengeUserId = args.purpose.userId;
397
+ + if (challengeUserId !== undefined && await ctx.db.query("erasedUsers").withIndex("by_userId", q => q.eq("userId", challengeUserId)).unique())
398
+ + throw new Error("User identity has been erased");
399
+ const emailCode = generateRandomToken();
400
+ const browserSecret = generateRandomToken();
401
+ const challengeId = await ctx.db.insert("challenges", {
402
+ @@ -496,6 +499,9 @@
403
+ );
404
+ return claimFailure("INVALID_CHALLENGE");
405
+ }
406
+ + const challengeUserId = row.purpose.userId;
407
+ + if (challengeUserId !== undefined && await ctx.db.query("erasedUsers").withIndex("by_userId", q => q.eq("userId", challengeUserId)).unique())
408
+ + return claimFailure("INVALID_CHALLENGE");
409
+ // At exactly `expiresAt` the link is expired, like in the cleanup loop.
410
+ if (row.expiresAt <= Date.now()) {
411
+ console.warn(
412
+ --- a/src/components/email/schema.ts
413
+ +++ b/src/components/email/schema.ts
414
+ @@ -2,6 +2,7 @@
415
+ import { v } from "convex/values";
416
+
417
+ export default defineSchema({
418
+ + erasedUsers: defineTable({ userId: v.string(), erasedAt: v.number() }).index("by_userId", ["userId"]),
419
+ // One row for each verified email address.
420
+ //
421
+ // Invariants the component keeps true:
422
+ --- a/src/components/email/verifiedEmails.ts
423
+ +++ b/src/components/email/verifiedEmails.ts
424
+ @@ -114,3 +114,18 @@
425
+ return null;
426
+ },
427
+ });
428
+ +
429
+ +/** App-server only. Establish a permanent fence and delete bounded attributed rows. */
430
+ +export const eraseUserBatch = mutation({
431
+ + args: { userId: v.string() },
432
+ + returns: v.object({ emailsDeleted: v.number(), challengesDeleted: v.number(), complete: v.boolean() }),
433
+ + handler: async (ctx, { userId }) => {
434
+ + const tombstone = await ctx.db.query("erasedUsers").withIndex("by_userId", q => q.eq("userId", userId)).unique();
435
+ + if (!tombstone) await ctx.db.insert("erasedUsers", { userId, erasedAt: Date.now() });
436
+ + const emails = await ctx.db.query("verifiedEmails").withIndex("by_userId", q => q.eq("userId", userId)).take(100);
437
+ + const challenges = await ctx.db.query("challenges").withIndex("by_purpose_userId", q => q.eq("purpose.userId", userId)).take(100);
438
+ + for (const row of emails) await ctx.db.delete("verifiedEmails", row._id);
439
+ + for (const row of challenges) await ctx.db.delete("challenges", row._id);
440
+ + return { emailsDeleted: emails.length, challengesDeleted: challenges.length, complete: emails.length < 100 && challenges.length < 100 };
441
+ + },
442
+ +});
443
+ --- a/src/components/github/_generated/component.ts
444
+ +++ b/src/components/github/_generated/component.ts
445
+ @@ -28,7 +28,7 @@
446
+ "mutation",
447
+ "internal",
448
+ { stateHash: string; ticketCodeHash: string },
449
+ - null | { encryptedPayload: string },
450
+ + null | { encryptedPayload: string; authorizationStartedAt?: number },
451
+ Name
452
+ >;
453
+ createAuthorizationRequest: FunctionReference<
454
+ --- a/src/components/google/_generated/component.ts
455
+ +++ b/src/components/google/_generated/component.ts
456
+ @@ -28,7 +28,7 @@
457
+ "mutation",
458
+ "internal",
459
+ { stateHash: string; ticketCodeHash: string },
460
+ - null | { encryptedPayload: string },
461
+ + null | { encryptedPayload: string; authorizationStartedAt?: number },
462
+ Name
463
+ >;
464
+ createAuthorizationRequest: FunctionReference<
465
+ --- a/src/components/google/convex.config.ts
466
+ +++ b/src/components/google/convex.config.ts
467
+ @@ -17,8 +17,9 @@
468
+ */
469
+ const component = defineComponent("authGoogle", {
470
+ env: {
471
+ - CLIENT_ID: v.string(),
472
+ - CLIENT_SECRET: v.string(),
473
+ + CLIENT_ID: v.optional(v.string()),
474
+ + CLIENT_SECRET: v.optional(v.string()),
475
+ + CALLBACK_URL: v.optional(v.string()),
476
+ },
477
+ });
478
+
479
+ --- a/src/components/oauth/_generated/component.ts
480
+ +++ b/src/components/oauth/_generated/component.ts
481
+ @@ -28,7 +28,7 @@
482
+ "mutation",
483
+ "internal",
484
+ { providerName: string; stateHash: string; ticketCodeHash: string },
485
+ - null | { encryptedPayload: string },
486
+ + null | { encryptedPayload: string; authorizationStartedAt?: number },
487
+ Name
488
+ >;
489
+ createAuthorizationRequest: FunctionReference<
490
+ --- a/src/components/oauth/provider.ts
491
+ +++ b/src/components/oauth/provider.ts
492
+ @@ -57,6 +57,7 @@
493
+ redirectTo: v.string(),
494
+ callbackUrl: v.string(),
495
+ codeVerifier: v.string(),
496
+ + authorizationStartedAt: v.optional(v.number()),
497
+ tokenEndpoint: v.string(),
498
+ userInfoEndpoints: v.optional(v.record(v.string(), v.string())),
499
+ issuers: v.optional(v.array(v.string())),
500
+ @@ -80,6 +81,7 @@
501
+ redirectTo: doc.redirectTo,
502
+ callbackUrl: doc.callbackUrl,
503
+ codeVerifier: doc.codeVerifier,
504
+ + ...(doc.authorizationStartedAt === undefined ? {} : { authorizationStartedAt: doc.authorizationStartedAt }),
505
+ tokenEndpoint: doc.tokenEndpoint,
506
+ userInfoEndpoints: doc.userInfoEndpoints,
507
+ issuers: doc.issuers,
508
+ @@ -99,6 +101,7 @@
509
+ stateHash: v.string(),
510
+ ticketCodeHash: v.string(),
511
+ encryptedPayload: v.string(),
512
+ + authorizationStartedAt: v.optional(v.number()),
513
+ },
514
+ returns: v.null(),
515
+ handler: async (ctx, args) =>
516
+ @@ -120,6 +123,7 @@
517
+ v.null(),
518
+ v.object({
519
+ encryptedPayload: v.string(),
520
+ + authorizationStartedAt: v.optional(v.number()),
521
+ }),
522
+ ),
523
+ handler: async (ctx, args) =>
524
+ --- a/src/components/password/_generated/component.ts
525
+ +++ b/src/components/password/_generated/component.ts
526
+ @@ -24,6 +24,7 @@
527
+ export type ComponentApi<Name extends string | undefined = string | undefined> =
528
+ {
529
+ public: {
530
+ + eraseUserPasswords: FunctionReference<"mutation", "internal", { userId: string }, { complete: boolean; deleted: number }, Name>;
531
+ setPassword: FunctionReference<
532
+ "mutation",
533
+ "internal",
534
+ --- a/src/components/password/public.ts
535
+ +++ b/src/components/password/public.ts
536
+ @@ -68,6 +68,7 @@
537
+ ctx,
538
+ { userId, password, minimumLength },
539
+ ): Promise<SetPasswordResult> => {
540
+ + if (await erasedUser(ctx, userId)) throw new Error("Password account is unavailable.");
541
+ const userError = validateNewPassword(password, minimumLength);
542
+ if (userError !== null) {
543
+ return { success: false, userError };
544
+ @@ -103,6 +104,7 @@
545
+ args: { userId: v.string(), password: v.string() },
546
+ returns: verifyPasswordResult,
547
+ handler: async (ctx, { userId, password }): Promise<VerifyPasswordResult> => {
548
+ + if (await erasedUser(ctx, userId)) return { success: false, userError: { error: "INVALID_CREDENTIALS" } };
549
+ const status = await rateLimiter.limit(ctx, "verifyPassword", {
550
+ key: userId,
551
+ });
552
+ @@ -158,3 +160,20 @@
553
+ .withIndex("by_userId", (q) => q.eq("userId", userId))
554
+ .unique();
555
+ }
556
+ +
557
+ +/** App-server-only bounded erasure; tombstone prevents old-user recreation. */
558
+ +export const eraseUserPasswords = mutation({
559
+ + args: { userId: v.string() },
560
+ + returns: v.object({ complete: v.boolean(), deleted: v.number() }),
561
+ + handler: async (ctx, { userId }) => {
562
+ + if (!userId) throw new Error("Missing user ID.");
563
+ + if (!(await erasedUser(ctx, userId)))
564
+ + await ctx.db.insert("erasedUsers", { userId, erasedAt: Date.now() });
565
+ + const rows = await ctx.db.query("passwords").withIndex("by_userId", q => q.eq("userId", userId)).take(101);
566
+ + for (const row of rows.slice(0, 100)) await ctx.db.delete("passwords", row._id);
567
+ + return { complete: rows.length <= 100, deleted: Math.min(rows.length, 100) };
568
+ + },
569
+ +});
570
+ +async function erasedUser(ctx: QueryCtx, userId: string) {
571
+ + return await ctx.db.query("erasedUsers").withIndex("by_userId", q => q.eq("userId", userId)).unique();
572
+ +}
573
+ --- a/src/components/password/schema.ts
574
+ +++ b/src/components/password/schema.ts
575
+ @@ -2,6 +2,7 @@
576
+ import { v } from "convex/values";
577
+
578
+ export default defineSchema({
579
+ + erasedUsers: defineTable({userId: v.string(), erasedAt: v.number()}).index("by_userId", ["userId"]),
580
+ passwords: defineTable({
581
+ userId: v.string(),
582
+ passwordHashPHC: v.string(), // format: https://github.com/C2SP/C2SP/blob/main/phc-strings.md
583
+ --- a/src/components/username/_generated/component.ts
584
+ +++ b/src/components/username/_generated/component.ts
585
+ @@ -24,6 +24,7 @@
586
+ export type ComponentApi<Name extends string | undefined = string | undefined> =
587
+ {
588
+ public: {
589
+ + eraseUser: FunctionReference<"mutation", "internal", { userId: string }, { deleted: boolean }, Name>;
590
+ deleteUsername: FunctionReference<
591
+ "mutation",
592
+ "internal",
593
+ --- a/src/components/username/public.ts
594
+ +++ b/src/components/username/public.ts
595
+ @@ -36,6 +36,8 @@
596
+ args: { userId: v.string(), username: v.string() },
597
+ returns: setUsernameResult,
598
+ handler: async (ctx, { userId, username }): Promise<SetUsernameResult> => {
599
+ + if (await ctx.db.query("erasedUsers").withIndex("by_userId", q => q.eq("userId", userId)).unique())
600
+ + throw new Error("User identity has been erased");
601
+ const userError = validateUsernameFormat(username);
602
+ if (userError !== null) {
603
+ return { success: false, userError };
604
+ @@ -117,6 +119,20 @@
605
+ },
606
+ });
607
+
608
+ +/** Permanently fence the old user ID and remove its username. App-server only. */
609
+ +export const eraseUser = mutation({
610
+ + args: { userId: v.string() },
611
+ + returns: v.object({ deleted: v.boolean() }),
612
+ + handler: async (ctx, { userId }) => {
613
+ + const tombstone = await ctx.db.query("erasedUsers").withIndex("by_userId", q => q.eq("userId", userId)).unique();
614
+ + if (!tombstone) await ctx.db.insert("erasedUsers", { userId, erasedAt: Date.now() });
615
+ + const row = await rowByUserId(ctx, userId);
616
+ + if (!row) return { deleted: false };
617
+ + await ctx.db.delete("usernames", row._id);
618
+ + return { deleted: true };
619
+ + },
620
+ +});
621
+ +
622
+ function rowByUserId(
623
+ ctx: QueryCtx,
624
+ userId: string,
625
+ --- a/src/components/username/schema.ts
626
+ +++ b/src/components/username/schema.ts
627
+ @@ -2,6 +2,7 @@
628
+ import { v } from "convex/values";
629
+
630
+ export default defineSchema({
631
+ + erasedUsers: defineTable({ userId: v.string(), erasedAt: v.number() }).index("by_userId", ["userId"]),
632
+ // One row for each user that has a username. The component only sees an
633
+ // opaque app `userId` string.
634
+ usernames: defineTable({
635
+ --- a/src/lib/oauth/authorize.ts
636
+ +++ b/src/lib/oauth/authorize.ts
637
+ @@ -57,6 +57,8 @@
638
+ providerName: string;
639
+ /** Origins `redirectTo` may point at, already validated and normalized. */
640
+ allowedOrigins: string[];
641
+ + /** Optional server-side routing envelope; the browser keeps the original state. */
642
+ + authorizationState?: (state: string) => Promise<string>;
643
+ /** The provider's authorization endpoint (a full URL). */
644
+ authorizationEndpoint: string;
645
+ /** Scopes to request. Left off the URL entirely when empty. */
646
+ @@ -120,7 +122,7 @@
647
+ response_type: "code",
648
+ client_id: clientId,
649
+ redirect_uri: callbackUrl,
650
+ - state,
651
+ + state: options.authorizationState ? await options.authorizationState(state) : state,
652
+ // Every provider gets a challenge. One that does not implement PKCE
653
+ // ignores the parameters, which RFC 6749 requires of it.
654
+ code_challenge: await sha256Base64Url(codeVerifier),
655
+ --- a/src/lib/oauth/callback.ts
656
+ +++ b/src/lib/oauth/callback.ts
657
+ @@ -265,6 +265,7 @@
658
+
659
+ /** What every component's claimed authorization request has in common. */
660
+ export type ClaimedRequest = {
661
+ + authorizationStartedAt?: number;
662
+ stateHash: string;
663
+ redirectTo: string;
664
+ callbackUrl: string;
665
+ @@ -277,6 +278,7 @@
666
+
667
+ /** The fields of a new ticket, for `mintTicket` to store. */
668
+ export type MintedTicket = {
669
+ + authorizationStartedAt?: number;
670
+ ticketCodeHash: string;
671
+ encryptedPayload: string;
672
+ };
673
+ @@ -430,6 +432,7 @@
674
+
675
+ const ticketCode = generateRandomToken();
676
+ await options.mintTicket(authRequest, {
677
+ + ...(authRequest.authorizationStartedAt === undefined ? {} : { authorizationStartedAt: authRequest.authorizationStartedAt }),
678
+ ticketCodeHash: await sha256Hex(ticketCode),
679
+ encryptedPayload: await encryptTicketPayload(
680
+ ticketCode,
681
+ --- a/src/lib/oauth/dbHelpers.ts
682
+ +++ b/src/lib/oauth/dbHelpers.ts
683
+ @@ -58,7 +58,7 @@
684
+ Doc extends AuthorizationRequestContract,
685
+ >(
686
+ ctx: MutationCtx,
687
+ - fields: Omit<WithoutSystemFields<Doc>, "callbackUrl" | "expiresAt">,
688
+ + fields: Omit<WithoutSystemFields<Doc>, "callbackUrl" | "expiresAt" | "authorizationStartedAt">,
689
+ ): Promise<{ callbackUrl: string }> {
690
+ // System env vars are only visible inside components on backends with
691
+ // convex/convex-backend@64c163a (July 2026); cloud always has it,
692
+ @@ -72,10 +72,11 @@
693
+ "functions.",
694
+ );
695
+ }
696
+ - const callbackUrl = `${siteUrl}${CALLBACK_PATH}`;
697
+ + const callbackUrl = process.env.CALLBACK_URL || `${siteUrl}${CALLBACK_PATH}`;
698
+ await ctx.db.insert("authorizationRequests", {
699
+ ...fields,
700
+ callbackUrl,
701
+ + authorizationStartedAt: Date.now(),
702
+ expiresAt: Date.now() + AUTHORIZATION_REQUEST_TTL_MS,
703
+ });
704
+ return { callbackUrl };
705
+ @@ -159,7 +160,7 @@
706
+ stateHash: string;
707
+ match?: (ticket: Doc) => boolean;
708
+ },
709
+ -): Promise<{ encryptedPayload: string } | null> {
710
+ +): Promise<{ encryptedPayload: string; authorizationStartedAt?: number } | null> {
711
+ // The same assertion as in claimAuthorizationRequest, for the same reason.
712
+ const ticket = (await ctx.db
713
+ .query("tickets")
714
+ @@ -181,5 +182,5 @@
715
+ return null;
716
+ }
717
+ await ctx.db.delete("tickets", ticket._id);
718
+ - return { encryptedPayload: ticket.encryptedPayload };
719
+ + return { encryptedPayload: ticket.encryptedPayload, ...(ticket.authorizationStartedAt === undefined ? {} : { authorizationStartedAt: ticket.authorizationStartedAt }) };
720
+ }
721
+ --- a/src/lib/oauth/providerFunctions.ts
722
+ +++ b/src/lib/oauth/providerFunctions.ts
723
+ @@ -48,7 +48,7 @@
724
+ */
725
+ const createRequestArgs = v
726
+ .object(authorizationRequestFields)
727
+ - .omit("callbackUrl", "expiresAt");
728
+ + .omit("callbackUrl", "expiresAt", "authorizationStartedAt");
729
+
730
+ /** The fields of a claimed request that is still live. */
731
+ const claimedRequestFields = v
732
+ @@ -121,6 +121,7 @@
733
+ redirectTo: claimed.doc.redirectTo,
734
+ callbackUrl: claimed.doc.callbackUrl,
735
+ codeVerifier: claimed.doc.codeVerifier,
736
+ + ...(claimed.doc.authorizationStartedAt === undefined ? {} : { authorizationStartedAt: claimed.doc.authorizationStartedAt }),
737
+ };
738
+ },
739
+ });
740
+ @@ -137,7 +138,7 @@
741
+ ticketCodeHash: v.string(),
742
+ stateHash: v.string(),
743
+ },
744
+ - returns: v.union(v.null(), v.object({ encryptedPayload: v.string() })),
745
+ + returns: v.union(v.null(), v.object({ encryptedPayload: v.string(), authorizationStartedAt: v.optional(v.number()) })),
746
+ handler: async (ctx, args) =>
747
+ await dbHelpers.claimTicket<SharedTicketDocument>(ctx, args),
748
+ });
749
+ --- a/src/lib/oauth/redemption.ts
750
+ +++ b/src/lib/oauth/redemption.ts
751
+ @@ -144,7 +144,17 @@
752
+ claimTicket: (
753
+ ctx: MutationCtx,
754
+ args: { ticketCodeHash: string; stateHash: string },
755
+ - ) => Promise<{ encryptedPayload: string } | null>;
756
+ + ) => Promise<{
757
+ + encryptedPayload: string;
758
+ + authorizationStartedAt?: number;
759
+ + } | null>;
760
+ + enforceIdentityErasure?: boolean;
761
+ + /** Optional server-side consumer; undefined marks legacy tickets. */
762
+ + checkAuthorizationStart?: (
763
+ + ctx: MutationCtx,
764
+ + profile: Profile,
765
+ + startedAt: number | undefined,
766
+ + ) => Promise<void>;
767
+ /** Map what the provider attested to the account profile. */
768
+ profile: (payload: Payload) => Profile;
769
+ }) {
770
+ @@ -175,6 +185,17 @@
771
+ `Profile mapping for provider "${options.providerName}" returned no id`,
772
+ );
773
+ }
774
+ +
775
+ + if (options.enforceIdentityErasure)
776
+ + await ctx.convexAuth.assertAuthorizationStart(
777
+ + profile.id,
778
+ + ticket.authorizationStartedAt,
779
+ + );
780
+ + await options.checkAuthorizationStart?.(
781
+ + ctx,
782
+ + profile,
783
+ + ticket.authorizationStartedAt,
784
+ + );
785
+
786
+ // The same redemption flow serves a first sign-in and a return visit, so
787
+ // resolve the identity to pick a path. This handler is a mutation, so the
788
+ --- a/src/lib/oauth/schema.ts
789
+ +++ b/src/lib/oauth/schema.ts
790
+ @@ -24,6 +24,8 @@
791
+ * ignores the parameters.
792
+ */
793
+ codeVerifier: v.string(),
794
+ + /** Server time at original authorization start; absent on legacy records. */
795
+ + authorizationStartedAt: v.optional(v.number()),
796
+ /** The callback rejects requests older than this. */
797
+ expiresAt: v.number(),
798
+ };
799
+ @@ -41,6 +43,8 @@
800
+ * or server that initiated the flow.
801
+ */
802
+ stateHash: v.string(),
803
+ + /** Inherited from the claimed request, never from a client. */
804
+ + authorizationStartedAt: v.optional(v.number()),
805
+ /**
806
+ * sha256 of the server-minted ticket code. The raw value appears only
807
+ * in the callback redirect URL and is never stored.
808
+ --- a/src/lib/types.ts
809
+ +++ b/src/lib/types.ts
810
+ @@ -367,6 +367,10 @@
811
+ * Returns `null` when no user id is found for the account.
812
+ */
813
+ resolveUserId(providerAccountId: string): Promise<string | null>;
814
+ + assertAuthorizationStart(
815
+ + providerAccountId: string,
816
+ + startedAt: number | undefined,
817
+ + ): Promise<void>;
818
+ /**
819
+ * Revokes every session of the signed-in user other than the current one
820
+ * (the JWT's subject). Returns the number of active (non-expired)
821
+ --- a/src/methods/google/server.ts
822
+ +++ b/src/methods/google/server.ts
823
+ @@ -5,6 +5,7 @@
824
+ * @module
825
+ */
826
+ import { Infer, v } from "convex/values";
827
+ +import type { GenericMutationCtx, GenericDataModel } from "convex/server";
828
+ import type { UserCallbacks } from "../../lib/types.ts";
829
+ import type { AuthCore } from "../../server/setup.ts";
830
+ import { buildStartSignIn } from "../../lib/oauth/authorize.ts";
831
+ @@ -70,6 +71,14 @@
832
+ * for open-redirect prevention.
833
+ */
834
+ allowedRedirectOrigins: string[];
835
+ + /** Server-only pre-sign-in check; undefined is legacy authorization proof. */
836
+ + checkAuthorizationStart?: (
837
+ + ctx: GenericMutationCtx<GenericDataModel>,
838
+ + profile: GoogleProfile,
839
+ + startedAt: number | undefined,
840
+ + ) => Promise<void>;
841
+ + /** Optional signed state envelope for a shared callback. */
842
+ + authorizationState?: (state: string) => Promise<string>;
843
+ };
844
+
845
+ /**
846
+ @@ -122,6 +131,7 @@
847
+ const startSignIn = buildStartSignIn({
848
+ providerName: PROVIDER_NAME,
849
+ allowedOrigins,
850
+ + authorizationState: options.authorizationState,
851
+ authorizationEndpoint: AUTHORIZATION_ENDPOINT,
852
+ scopes: SCOPES,
853
+ createAuthorizationRequest:
854
+ @@ -133,7 +143,9 @@
855
+ { claims?: OidcClaims }
856
+ >({
857
+ providerName: PROVIDER_NAME,
858
+ + enforceIdentityErasure: true,
859
+ authMutation,
860
+ + checkAuthorizationStart: options.checkAuthorizationStart,
861
+ claimTicket: (ctx, args) =>
862
+ ctx.runMutation(options.component.provider.claimTicket, args),
863
+ profile: (payload) => normalizeGoogleProfile(payload.claims),
864
+ --- a/src/server/setup.ts
865
+ +++ b/src/server/setup.ts
866
+ @@ -393,6 +393,24 @@
867
+ createUserHandle: await createFunctionHandle(createUser),
868
+ });
869
+ },
870
+ + assertAuthorizationStart: async (
871
+ + providerAccountId: string,
872
+ + startedAt: number | undefined,
873
+ + ): Promise<void> => {
874
+ + const cutoff = await ctx.runQuery(
875
+ + component.public.getIdentityErasureCutoff,
876
+ + { provider: name, providerAccountId },
877
+ + );
878
+ + if (cutoff !== null) {
879
+ + if (startedAt === undefined || startedAt <= cutoff)
880
+ + throw new Error(
881
+ + "Authorization predates account erasure or lacks proof.",
882
+ + );
883
+ + throw new Error(
884
+ + "Registration for this identity is unavailable pending an explicit re-registration ceremony.",
885
+ + );
886
+ + }
887
+ + },
888
+ resolveUserId: async (
889
+ providerAccountId: string,
890
+ ): Promise<string | null> => {