Repository navigation
Add verified account email change flow #645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
1bbc48a
f89f359
0fe8731
5947ff6
de3288f
86b3924
111dd40
7f2d278
0036e4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| ALTER TABLE users ADD COLUMN stable_user_id TEXT; | ||
|
|
||
| CREATE UNIQUE INDEX IF NOT EXISTS idx_users_stable_user_id | ||
| ON users(stable_user_id) | ||
| WHERE stable_user_id IS NOT NULL; | ||
|
|
||
| CREATE TABLE IF NOT EXISTS pending_email_changes ( | ||
| id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, | ||
| user_id INTEGER NOT NULL, | ||
| new_email TEXT NOT NULL, | ||
| token_hash TEXT NOT NULL UNIQUE, | ||
| expires_at INTEGER NOT NULL, | ||
| created_at TEXT NOT NULL DEFAULT (CURRENT_TIMESTAMP), | ||
| FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE | ||
| ); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_pending_email_changes_user_id | ||
| ON pending_email_changes(user_id); | ||
|
|
||
| CREATE UNIQUE INDEX IF NOT EXISTS idx_pending_email_changes_new_email | ||
| ON pending_email_changes(new_email); | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_pending_email_changes_token_hash | ||
| ON pending_email_changes(token_hash); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ import { buildCommunitySnapshotKvKey } from '#worker/community/snapshot.ts' | |
| import { storageRunnerRpc } from '#worker/storage-runner.ts' | ||
| import { userScopedConnectorSessionKey } from '#worker/remote-connector/connector-session-key.ts' | ||
| import { type RemoteConnectorSessionExport } from '#worker/remote-connector/types.ts' | ||
| import { createStableUserIdFromEmail } from '#worker/user-id.ts' | ||
| import { resolveUserStableId } from '#worker/user-id.ts' | ||
|
|
||
| const accountExportSchemaVersion = 1 | ||
| const defaultExportPageSize = 100 | ||
|
|
@@ -32,6 +32,7 @@ const redactedColumnsByTable: Readonly<Record<string, ReadonlyArray<string>>> = | |
| email_verifications: ['token_hash'], | ||
| package_invocation_tokens: ['token_hash'], | ||
| password_resets: ['token_hash'], | ||
| pending_email_changes: ['token_hash'], | ||
| remote_connector_settings: ['encrypted_shared_secret'], | ||
| secret_entries: ['encrypted_value', 'lookup_hash'], | ||
| users: ['password_hash'], | ||
|
|
@@ -1107,20 +1108,19 @@ export async function resolveAccountExportDbUserId(input: { | |
| if (!email) { | ||
| throw new Error('Account export requires an authenticated user email.') | ||
| } | ||
| const stableUserId = await createStableUserIdFromEmail(email) | ||
| if (stableUserId !== input.mcpUserId) { | ||
| throw new Error( | ||
| 'Authenticated user identity did not match the account email.', | ||
| ) | ||
| } | ||
| const row = await input.env.APP_DB.prepare( | ||
| `SELECT id FROM users WHERE email = ?`, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Export lookup breaks after changeMedium Severity Account export resolves the database user only by the caller email. After an email change, MCP export can still pass the previous address, the row is not found, and export fails even when Reviewed by Cursor Bugbot for commit 0036e4f. Configure here. |
||
| `SELECT id, email, stable_user_id FROM users WHERE email = ?`, | ||
| ) | ||
| .bind(email) | ||
| .first<{ id: number }>() | ||
| .first<{ id: number; email: string; stable_user_id: string | null }>() | ||
| if (!row) { | ||
| throw new Error('Authenticated account was not found.') | ||
| } | ||
| if ((await resolveUserStableId(row)) !== input.mcpUserId) { | ||
| throw new Error( | ||
| 'Authenticated user identity did not match the account email.', | ||
| ) | ||
| } | ||
| return row.id | ||
| } | ||
|
|
||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.