Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(auth): transact account deletion receipts

xd-bobo5f66a67f23a7
diff --git a/apps/desktop/src/main/__tests__/authAccountDeletionLifecycle.test.ts b/apps/desktop/src/main/__tests__/authAccountDeletionLifecycle.test.ts
index 66d3cce79e..e6a657685d 100644
--- a/apps/desktop/src/main/__tests__/authAccountDeletionLifecycle.test.ts
+++ b/apps/desktop/src/main/__tests__/authAccountDeletionLifecycle.test.ts
@@ -98,28 +98,38 @@ describe('desktop auth account-deletion lifecycle', () => {
expect(source.slice(logoutStart, logoutEnd)).toContain('clearAccountDeletionReceipt();');
});
- it('clears stale receipts as soon as a login selects an account', () => {
+ it('keeps the previous receipt while account selection is still cancellable', () => {
const start = source.indexOf('async function acceptLoginOutcome');
const end = source.indexOf('\n}\n\nasync function runLoginAction', start);
const body = source.slice(start, end);
- expect(body).toContain("if (outcome.status === 'ok' || outcome.status === 'select_account')");
- expect(body).toContain('removeSafe(ACCOUNT_DELETION_RECEIPT_KEY);');
- expect(body.indexOf('removeSafe(ACCOUNT_DELETION_RECEIPT_KEY);')).toBeLessThan(
- body.indexOf("if (outcome.status === 'select_account')"),
- );
+ expect(body).toContain("outcome.status === 'ok' || outcome.status === 'select_account'");
+ expect(body).not.toContain('removeSafe(ACCOUNT_DELETION_RECEIPT_KEY);');
+ expect(body).not.toContain('commitWithClearedAccountDeletionReceipt(');
});
- it('emits the restoration notice only after the final login commits', () => {
+ it('strictly clears the old receipt only inside the final login commit', () => {
const start = source.indexOf('async function completeLogin(');
const end = source.indexOf('\n}\n\nasync function acceptLoginOutcome', start);
const body = source.slice(start, end);
+ const helperStart = source.indexOf(
+ 'function commitWithClearedAccountDeletionReceipt(',
+ );
+ const helperEnd = source.indexOf('\n}\n\nfunction emptyAuthAccountVault', helperStart);
+ const helper = source.slice(helperStart, helperEnd);
- expect(body).toContain('removeSafe(ACCOUNT_DELETION_RECEIPT_KEY);');
+ expect(body).toContain('commitWithClearedAccountDeletionReceipt(() => {');
expect(body).toContain('accountDeletionRestoredNoticePending = deletionWasRestored;');
expect(body.indexOf('accountDeletionRestoredNoticePending =')).toBeLessThan(
body.indexOf('notifyRenderer();'),
);
+ expect(helper).toContain('fs.unlinkSync(filepath);');
+ expect(helper).toContain("code !== 'ENOENT'");
+ expect(helper).toContain("'CREDENTIAL_STORE_UNAVAILABLE'");
+ expect(helper).toContain('atomicWriteFileSync(filepath, previousEncrypted);');
+ expect(helper.indexOf('fs.unlinkSync(filepath);')).toBeLessThan(
+ helper.lastIndexOf('return commit();'),
+ );
});
it('single-flights terminal rejection through full account teardown', () => {
diff --git a/apps/desktop/src/main/__tests__/authPassiveSharedInstance.test.ts b/apps/desktop/src/main/__tests__/authPassiveSharedInstance.test.ts
index 52b2bfb147..6354e2158e 100644
--- a/apps/desktop/src/main/__tests__/authPassiveSharedInstance.test.ts
+++ b/apps/desktop/src/main/__tests__/authPassiveSharedInstance.test.ts
@@ -233,11 +233,8 @@ describe('passive shared-userData instance auth isolation', () => {
const acceptStart = authSource.indexOf('async function acceptLoginOutcome(');
const acceptEnd = authSource.indexOf('\n}\n\nasync function runLoginAction', acceptStart);
const acceptBody = authSource.slice(acceptStart, acceptEnd);
- const acceptGuard = acceptBody.indexOf('if (!isPassiveSharedUserDataInstance()) {');
- expect(acceptGuard).toBeGreaterThan(-1);
- expect(acceptBody.indexOf('removeSafe(ACCOUNT_DELETION_RECEIPT_KEY);')).toBeGreaterThan(
- acceptGuard,
- );
+ expect(acceptBody).not.toContain('removeSafe(ACCOUNT_DELETION_RECEIPT_KEY);');
+ expect(acceptBody).not.toContain('commitWithClearedAccountDeletionReceipt(');
const completeStart = authSource.indexOf('async function completeLogin(');
const completeEnd = authSource.indexOf('\n}\n\nasync function acceptLoginOutcome', completeStart);
@@ -247,10 +244,16 @@ describe('passive shared-userData instance auth isolation', () => {
expect(completeBody.indexOf('removeSafe(LEGACY_REFRESH_TOKEN_KEY);')).toBeGreaterThan(
completeGuard,
);
- expect(completeBody.indexOf('removeSafe(ACCOUNT_DELETION_RECEIPT_KEY);')).toBeGreaterThan(
- completeGuard,
- );
+ expect(completeBody).toContain('commitWithClearedAccountDeletionReceipt(() => {');
expect(completeBody.indexOf('clearReloginFlag();')).toBeGreaterThan(completeGuard);
+
+ const receiptCommit = sliceBody(
+ 'function commitWithClearedAccountDeletionReceipt(commit: () => void): void {',
+ '\n}\n',
+ );
+ expect(receiptCommit).toContain(
+ 'if (isPassiveSharedUserDataInstance()) return commit();',
+ );
});
it('冷启动确定性失效:passive 不删盘,非 passive 也只做 compare-and-delete', () => {
diff --git a/apps/desktop/src/main/authManager.ts b/apps/desktop/src/main/authManager.ts
index 1d4f79953b..d54ce2a573 100644
--- a/apps/desktop/src/main/authManager.ts
+++ b/apps/desktop/src/main/authManager.ts
@@ -620,6 +620,73 @@ function removeSafe(key: string): void {
}
}
+/**
+ * Delete the previous owner's account-deletion receipt as the final fallible
+ * step of an account transition. The encrypted bytes are restored if the
+ * synchronous owner publication throws, while an unlink failure prevents the
+ * new owner from being published at all.
+ */
+function commitWithClearedAccountDeletionReceipt(commit: () => void): void {
+ if (isPassiveSharedUserDataInstance()) return commit();
+ const filepath = path.join(SAFE_STORAGE_DIR(), `${ACCOUNT_DELETION_RECEIPT_KEY}.enc`);
+ let previousEncrypted: string | null;
+ try {
+ previousEncrypted = fs.readFileSync(filepath, 'utf8');
+ } catch (error) {
+ if ((error as NodeJS.ErrnoException)?.code === 'ENOENT') {
+ previousEncrypted = null;
+ } else {
+ logSafeStorageIssueOnce(
+ 'account transition receipt snapshot failed',
+ ACCOUNT_DELETION_RECEIPT_KEY,
+ error,
+ );
+ throw new AuthApiError(
+ 'CREDENTIAL_STORE_UNAVAILABLE',
+ 503,
+ 'Could not read the previous account deletion receipt',
+ );
+ }
+ }
+ try {
+ fs.unlinkSync(filepath);
+ } catch (error) {
+ if ((error as NodeJS.ErrnoException)?.code !== 'ENOENT') {
+ logSafeStorageIssueOnce(
+ 'account transition receipt delete failed',
+ ACCOUNT_DELETION_RECEIPT_KEY,
+ error,
+ );
+ throw new AuthApiError(
+ 'CREDENTIAL_STORE_UNAVAILABLE',
+ 503,
+ 'Could not clear the previous account deletion receipt',
+ );
+ }
+ }
+ try {
+ return commit();
+ } catch (error) {
+ if (previousEncrypted !== null) {
+ try {
+ atomicWriteFileSync(filepath, previousEncrypted);
+ } catch (restoreError) {
+ logSafeStorageIssueOnce(
+ 'account transition receipt restore failed',
+ ACCOUNT_DELETION_RECEIPT_KEY,
+ restoreError,
+ );
+ throw new AuthApiError(
+ 'CREDENTIAL_STORE_UNAVAILABLE',
+ 503,
+ 'Could not restore the previous account deletion receipt',
+ );
+ }
+ }
+ throw error;
+ }
+}
+
function emptyAuthAccountVault(): AuthAccountVault {
return { version: 1, activeAccountKey: null, resources: {}, passports: {} };
}
@@ -4124,35 +4191,36 @@ async function completeLogin(
await claimLegacyNamespaceForVerifiedUser(nextUser.id);
assertTransitionCurrent();
},
- commit: () => {
- pendingAccountToken = null;
- pendingAccountRefreshToken = null;
- pendingAccountMemberships = [];
- pendingAccountDeletionRestored = false;
- accessToken = outcome.accessToken;
- persistedRefreshTokenNeedsIdentityCheck = false;
- clearReplacementIntegrationReloadTimers();
- activateClientEndpointRealm(committedRealm);
- activeAuthRealm = committedRealm;
- if (!isPassiveSharedUserDataInstance()) {
- removeSafe(LEGACY_REFRESH_TOKEN_KEY);
- }
- lastAcceptedRefreshToken = outcome.refreshToken;
- if (!isPassiveSharedUserDataInstance()) {
- removeSafe(ACCOUNT_DELETION_RECEIPT_KEY);
- clearReloginFlag();
- }
- accountDeletionRestoredNoticePending = deletionWasRestored;
- // 显式登录解除本进程登出墓碑(passive / foreign-device)。
- passiveLocalSignOut = false;
- foreignDeviceLocalSignOut = false;
- currentUser = nextUser;
- commitCloudAppSession(currentUser.id);
- if (!isPassiveSharedUserDataInstance()) {
- canaryFlagStore.clear();
- }
- pendingAuthRealm = null;
- },
+ commit: () =>
+ commitWithClearedAccountDeletionReceipt(() => {
+ assertTransitionCurrent();
+ pendingAccountToken = null;
+ pendingAccountRefreshToken = null;
+ pendingAccountMemberships = [];
+ pendingAccountDeletionRestored = false;
+ accessToken = outcome.accessToken;
+ persistedRefreshTokenNeedsIdentityCheck = false;
+ clearReplacementIntegrationReloadTimers();
+ activateClientEndpointRealm(committedRealm);
+ activeAuthRealm = committedRealm;
+ if (!isPassiveSharedUserDataInstance()) {
+ removeSafe(LEGACY_REFRESH_TOKEN_KEY);
+ }
+ lastAcceptedRefreshToken = outcome.refreshToken;
+ if (!isPassiveSharedUserDataInstance()) {
+ clearReloginFlag();
+ }
+ accountDeletionRestoredNoticePending = deletionWasRestored;
+ // 显式登录解除本进程登出墓碑(passive / foreign-device)。
+ passiveLocalSignOut = false;
+ foreignDeviceLocalSignOut = false;
+ currentUser = nextUser;
+ commitCloudAppSession(currentUser.id);
+ if (!isPassiveSharedUserDataInstance()) {
+ canaryFlagStore.clear();
+ }
+ pendingAuthRealm = null;
+ }),
});
},
);
@@ -4191,13 +4259,6 @@ async function acceptLoginOutcome(
expectedLoginFlowEpoch = loginFlowEpoch,
): Promise<AuthFlowState> {
assertLoginFlowCurrent(expectedLoginFlowEpoch);
- if (outcome.status === 'ok' || outcome.status === 'select_account') {
- // Membership selection already establishes which passport owns the new
- // login. A receipt from the previous login must not survive this boundary.
- if (!isPassiveSharedUserDataInstance()) {
- removeSafe(ACCOUNT_DELETION_RECEIPT_KEY);
- }
- }
if (
(outcome.status === 'ok' || outcome.status === 'select_account') &&
outcome.accountDeletionRestored === true
diff --git a/apps/mobile/src/__tests__/accountDeletion.test.ts b/apps/mobile/src/__tests__/accountDeletion.test.ts
index 9d834e2b96..5a91e7a26f 100644
--- a/apps/mobile/src/__tests__/accountDeletion.test.ts
+++ b/apps/mobile/src/__tests__/accountDeletion.test.ts
@@ -47,13 +47,16 @@ describe("mobile account deletion", () => {
);
expect(context).toContain("'cindy.mobile.auth.accountDeletionReceipt'");
- expect(acceptBody).toContain(
- "if (outcome.status === 'ok' || outcome.status === 'select_account')",
+ const selectionPending = acceptBody.indexOf(
+ "if (outcome.status === 'select_account')",
);
- expect(
- acceptBody.indexOf("await persistAccountDeletionReceipt(null);"),
- ).toBeLessThan(
- acceptBody.indexOf("if (outcome.status === 'select_account')"),
+ const receiptCommit = acceptBody.indexOf(
+ "await commitWithClearedAccountDeletionReceipt(() => {",
+ );
+ expect(selectionPending).toBeGreaterThan(-1);
+ expect(receiptCommit).toBeGreaterThan(selectionPending);
+ expect(acceptBody.slice(0, selectionPending)).not.toContain(
+ "persistAccountDeletionReceipt(null)",
);
expect(acceptBody).toContain("pendingAccountDeletionRestoredRef.current =");
expect(acceptBody).toContain(
@@ -81,6 +84,25 @@ describe("mobile account deletion", () => {
expect(persistBody).not.toContain(
"deleteSecureItem(ACCOUNT_DELETION_RECEIPT_KEY).catch",
);
+ const transactionalClearStart = context.indexOf(
+ "const commitWithClearedAccountDeletionReceipt = useCallback",
+ );
+ const transactionalClearBody = context.slice(
+ transactionalClearStart,
+ context.indexOf("/* ── 登录人机验证", transactionalClearStart),
+ );
+ expect(transactionalClearBody).toContain(
+ "const previousRaw = await getSecureItem(",
+ );
+ expect(transactionalClearBody).toContain(
+ "await setSecureItem(ACCOUNT_DELETION_RECEIPT_KEY, previousRaw);",
+ );
+ expect(
+ transactionalClearBody.indexOf("await deleteSecureItem("),
+ ).toBeLessThan(
+ transactionalClearBody.indexOf("commit();"),
+ );
+ expect(transactionalClearBody).not.toContain("await commit()");
expect(requestBody).toContain("activeAuthRealmRef.current,\n );");
expect(confirmBody).toContain("await clearLocalSession();");
expect(confirmBody).not.toContain(
diff --git a/apps/mobile/src/__tests__/mobileAuthServerLogin.test.ts b/apps/mobile/src/__tests__/mobileAuthServerLogin.test.ts
index 6db3e29c84..798126fec5 100644
--- a/apps/mobile/src/__tests__/mobileAuthServerLogin.test.ts
+++ b/apps/mobile/src/__tests__/mobileAuthServerLogin.test.ts
@@ -480,7 +480,7 @@ describe('mobile auth-server login', () => {
'await clearAccountScopedRuntimeForSwitch();',
);
const receiptClear = switchBody.indexOf(
- 'await persistAccountDeletionReceipt(null);',
+ 'await commitWithClearedAccountDeletionReceipt(() => {',
runtimeClear,
);
const ownerCommit = switchBody.indexOf(
diff --git a/apps/mobile/src/auth/AuthContext.tsx b/apps/mobile/src/auth/AuthContext.tsx
index 5e15227534..621617cad2 100644
--- a/apps/mobile/src/auth/AuthContext.tsx
+++ b/apps/mobile/src/auth/AuthContext.tsx
@@ -401,6 +401,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
const [accountDeletionReceipt, setAccountDeletionReceipt] = useState<
string | null
>(null);
+ const accountDeletionReceiptRef = useRef<string | null>(null);
const [accountDeletionRestored, setAccountDeletionRestored] = useState(false);
const pendingLoginTicketRef = useRef<string | null>(null);
const pendingBindTicketRef = useRef<string | null>(null);
@@ -627,13 +628,13 @@ export function AuthProvider({ children }: { children: ReactNode }) {
ACCOUNT_DELETION_RECEIPT_KEY,
serializeAccountDeletionReceiptRecord(realm, receiptToken),
);
+ accountDeletionReceiptRef.current = receiptToken;
accountDeletionReceiptRealmRef.current = realm;
} else {
- // Account-bound transitions await this helper before publishing the
- // new owner. A failed durable delete must reject so their vault and
- // active-session transactions roll back instead of reviving the
- // previous identity's receipt after restart.
+ // Explicit receipt clearing must reject on storage failure instead
+ // of updating only the in-memory projection.
await deleteSecureItem(ACCOUNT_DELETION_RECEIPT_KEY);
+ accountDeletionReceiptRef.current = null;
accountDeletionReceiptRealmRef.current = null;
}
setAccountDeletionReceipt(receiptToken);
@@ -651,6 +652,51 @@ export function AuthProvider({ children }: { children: ReactNode }) {
[],
);
+ const commitWithClearedAccountDeletionReceipt = useCallback(
+ (commit: () => void): Promise<void> => {
+ const operation = async (): Promise<void> => {
+ const previousRaw = await getSecureItem(
+ ACCOUNT_DELETION_RECEIPT_KEY,
+ );
+ const previousToken = accountDeletionReceiptRef.current;
+ const previousRealm = accountDeletionReceiptRealmRef.current;
+ await deleteSecureItem(ACCOUNT_DELETION_RECEIPT_KEY);
+ try {
+ // Deliberately synchronous: after the post-delete cancellation
+ // checks pass, no event-loop turn may reopen the cancellation window
+ // before the new owner is published.
+ commit();
+ accountDeletionReceiptRef.current = null;
+ accountDeletionReceiptRealmRef.current = null;
+ setAccountDeletionReceipt(null);
+ } catch (error) {
+ // Add Account can be cancelled while SecureStore is deleting the
+ // previous owner's receipt. Restore the exact opaque record before
+ // releasing the receipt queue so cancellation cannot consume it.
+ if (previousRaw === null) {
+ await deleteSecureItem(ACCOUNT_DELETION_RECEIPT_KEY);
+ } else {
+ await setSecureItem(ACCOUNT_DELETION_RECEIPT_KEY, previousRaw);
+ }
+ accountDeletionReceiptRef.current = previousToken;
+ accountDeletionReceiptRealmRef.current = previousRealm;
+ setAccountDeletionReceipt(previousToken);
+ throw error;
+ }
+ };
+ const run = accountDeletionReceiptMutationRef.current.then(
+ operation,
+ operation,
+ );
+ accountDeletionReceiptMutationRef.current = run.then(
+ () => undefined,
+ () => undefined,
+ );
+ return run;
+ },
+ [],
+ );
+
/* ── 登录人机验证(Turnstile 托管挑战页,按 requiredFor 控制邮箱/短信发码)── */
const captchaConfigRef = useRef<CaptchaConfig | null>(null);
const [captchaChallenge, setCaptchaChallenge] = useState<{ url: string } | null>(null);
@@ -849,12 +895,6 @@ export function AuthProvider({ children }: { children: ReactNode }) {
): Promise<void> => {
await deleteSecureItem(PENDING_OAUTH_KEY).catch(() => undefined);
assertLoginFlowCurrent(expectedLoginFlowEpoch);
- if (outcome.status === 'ok' || outcome.status === 'select_account') {
- // 成功登录后,当前会话已明确属于本次登录的 passport。无论是否恢复了
- // 注销中的账号,都不能继续保留此前其他账号留下的查询 receipt。
- await persistAccountDeletionReceipt(null);
- assertLoginFlowCurrent(expectedLoginFlowEpoch);
- }
pendingAccountTokenRef.current =
outcome.status === 'select_account'
@@ -905,7 +945,6 @@ export function AuthProvider({ children }: { children: ReactNode }) {
const deletionWasRestored =
outcome.accountDeletionRestored === true ||
pendingAccountDeletionRestoredRef.current;
- pendingAccountDeletionRestoredRef.current = false;
const committedRealm = pendingAuthRealmRef.current ?? BUILD_AUTH_REGION;
const pendingMembership = pendingAccountMembershipsRef.current.find(
(membership) => membership.id === outcome.membership.id,
@@ -965,38 +1004,45 @@ export function AuthProvider({ children }: { children: ReactNode }) {
assertLoginFlowCurrent(expectedLoginFlowEpoch);
}
- // No await is allowed between the final cancellation check and
- // publishing the new in-memory owner. The vault transaction stays
- // owned through runtime cleanup and this synchronous commit, so a
- // cancelled Add Account flow restores both durable records.
- activateMobileSessionRealm(committedRealm);
- activeAuthRealmRef.current = committedRealm;
- pendingLoginTicketRef.current = null;
- pendingAccountTokenRef.current = null;
- pendingAccountRefreshTokenRef.current = null;
- pendingAccountMembershipsRef.current = [];
- pendingBindTicketRef.current = null;
- pendingSsoVerificationTicketRef.current = null;
- pendingAuthRealmRef.current = null;
- setToken(outcome.accessToken);
- applyUser(
- mergeMembershipWithExisting(
- outcome.membership,
- userRef.current,
- passportId || undefined,
- ),
- );
- additionalLoginRef.current = false;
- sessionRecoverySuspendedRef.current = false;
- setAccountGeneration((value) => value + 1);
- updateLoginState(
- reduceAuthFlow(loginStateRef.current, {
- type: 'outcome',
- outcome,
- }),
- );
- // 只有 resource token、用户资料与 refresh token 全部落地后才发布恢复提示。
- setAccountDeletionRestored(deletionWasRestored);
+ await commitWithClearedAccountDeletionReceipt(() => {
+ if (authGenerationRef.current !== generation) {
+ throw authCodeError('AUTH_FLOW_SUPERSEDED');
+ }
+ assertLoginFlowCurrent(expectedLoginFlowEpoch);
+
+ // Receipt deletion and owner publication are one transaction.
+ // The receipt helper restores the opaque record if Add Account
+ // was cancelled while SecureStore was deleting it.
+ pendingAccountDeletionRestoredRef.current = false;
+ activateMobileSessionRealm(committedRealm);
+ activeAuthRealmRef.current = committedRealm;
+ pendingLoginTicketRef.current = null;
+ pendingAccountTokenRef.current = null;
+ pendingAccountRefreshTokenRef.current = null;
+ pendingAccountMembershipsRef.current = [];
+ pendingBindTicketRef.current = null;
+ pendingSsoVerificationTicketRef.current = null;
+ pendingAuthRealmRef.current = null;
+ setToken(outcome.accessToken);
+ applyUser(
+ mergeMembershipWithExisting(
+ outcome.membership,
+ userRef.current,
+ passportId || undefined,
+ ),
+ );
+ additionalLoginRef.current = false;
+ sessionRecoverySuspendedRef.current = false;
+ setAccountGeneration((value) => value + 1);
+ updateLoginState(
+ reduceAuthFlow(loginStateRef.current, {
+ type: 'outcome',
+ outcome,
+ }),
+ );
+ // 只有 resource token、用户资料与 refresh token 全部落地后才发布恢复提示。
+ setAccountDeletionRestored(deletionWasRestored);
+ });
},
);
return true;
@@ -1030,8 +1076,8 @@ export function AuthProvider({ children }: { children: ReactNode }) {
applyUser,
assertLoginFlowCurrent,
clearAccountScopedRuntimeForSwitch,
+ commitWithClearedAccountDeletionReceipt,
loadMe,
- persistAccountDeletionReceipt,
scheduleCanaryChannelSync,
scheduleXdOrgBetaDefault,
refreshSavedAccountsSnapshot,
@@ -1273,6 +1319,8 @@ export function AuthProvider({ children }: { children: ReactNode }) {
}
: null);
if (storedDeletionReceipt) {
+ accountDeletionReceiptRef.current =
+ storedDeletionReceipt.receiptToken;
accountDeletionReceiptRealmRef.current = storedDeletionReceipt.realm;
setAccountDeletionReceipt(storedDeletionReceipt.receiptToken);
// Older builds stored only the opaque receipt; migrate it atomically
@@ -2306,33 +2354,30 @@ export function AuthProvider({ children }: { children: ReactNode }) {
throw authCodeError('AUTH_FLOW_SUPERSEDED');
}
- // The deletion receipt belongs to the previous login identity, not the
- // physical device. Clear its durable token, realm and restored banner at the
- // same account boundary as the other runtime projections. This is deliberately
- // the final awaited mutation before the synchronous owner commit below.
- await persistAccountDeletionReceipt(null);
- if (authGenerationRef.current !== generation) {
- throw authCodeError('AUTH_FLOW_SUPERSEDED');
- }
- pendingAccountDeletionRestoredRef.current = false;
- setAccountDeletionRestored(false);
-
- // Publish the new owner synchronously while the vault
- // transaction still owns activeAccountKey and AUTH_SESSION_KEY.
- activateMobileSessionRealm(realm!);
- activeAuthRealmRef.current = realm!;
- pendingAuthRealmRef.current = null;
- setToken(pair!.accessToken);
- applyUser(
- mergeMembershipWithExisting(
- pair!.membership,
- null,
- metadata.passportId,
- ),
- );
- sessionRecoverySuspendedRef.current = false;
- updateLoginState(null);
- setAccountGeneration((value) => value + 1);
+ await commitWithClearedAccountDeletionReceipt(() => {
+ if (authGenerationRef.current !== generation) {
+ throw authCodeError('AUTH_FLOW_SUPERSEDED');
+ }
+ pendingAccountDeletionRestoredRef.current = false;
+ setAccountDeletionRestored(false);
+
+ // Publish the new owner synchronously while the vault and
+ // receipt transactions are both still owned.
+ activateMobileSessionRealm(realm!);
+ activeAuthRealmRef.current = realm!;
+ pendingAuthRealmRef.current = null;
+ setToken(pair!.accessToken);
+ applyUser(
+ mergeMembershipWithExisting(
+ pair!.membership,
+ null,
+ metadata.passportId,
+ ),
+ );
+ sessionRecoverySuspendedRef.current = false;
+ updateLoginState(null);
+ setAccountGeneration((value) => value + 1);
+ });
},
);
} catch (error) {
@@ -2369,8 +2414,8 @@ export function AuthProvider({ children }: { children: ReactNode }) {
[
applyUser,
clearAccountScopedRuntimeForSwitch,
+ commitWithClearedAccountDeletionReceipt,
loadMe,
- persistAccountDeletionReceipt,
refreshSavedAccountsSnapshot,
scheduleCanaryChannelSync,
scheduleXdOrgBetaDefault,