Repository navigation
Add iOS account deletion and legal links #7645
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
Merged
Merged
Changes from 18 commits
Commits
Show all changes
91 commits
Select commit
Hold shift + click to select a range
16e2824
Add iOS account deletion and legal links
azooz2003-bit 0f88b97
Fix account deletion review issues
azooz2003-bit cf18f1a
Merge remote-tracking branch 'origin/main' into feat-ios-account-dele…
azooz2003-bit 760c4d9
Complete account deletion cleanup
azooz2003-bit aeedf88
Guard deleted account billing webhooks
azooz2003-bit ebaf859
Split mobile settings account review sections
azooz2003-bit 31808e1
Fix mobile settings section imports
azooz2003-bit 0f37717
Bound account deletion cleanup failures
azooz2003-bit b426270
Harden account deletion retries
azooz2003-bit 79edd76
Avoid billing purchase test mock leakage
azooz2003-bit d6e7ec5
Block account deletion race windows
azooz2003-bit 7150941
Close account deletion race windows
azooz2003-bit 02ce6e4
Treat post-delete cleanup as terminal
azooz2003-bit ffce0ac
Handle out-of-order subscription updates
azooz2003-bit d5e0971
Order account deletion cleanup safely
azooz2003-bit f7c181c
Avoid subscription primary key updates
azooz2003-bit a5f36a8
Attempt all account deletion VM teardown
azooz2003-bit b9fa4a2
Delete vault account data in bounded batches
azooz2003-bit b79f618
Scrub retained user references during account deletion
azooz2003-bit 63646bc
Parallelize vault object cleanup during account deletion
azooz2003-bit 8d68a59
Scrub team billing owner references on account deletion
azooz2003-bit 49ed190
Restore deletion metadata on cleanup failure
azooz2003-bit dba2b28
Close account deletion privacy gaps
azooz2003-bit ac590ae
Preserve visible account deletion failures
azooz2003-bit b12e742
Close account deletion residual gaps
azooz2003-bit f3d21a6
Handle local account deletion transport failures
azooz2003-bit 000bb3f
Split account deletion Swift helpers
azooz2003-bit 74c71aa
Keep destructive deletion failures retryable
azooz2003-bit e6e792c
Classify irreversible deletion cleanup safely
azooz2003-bit 3f2d3a5
Surface incomplete deletion cleanup on iOS
azooz2003-bit 41a10e4
Keep deletion retries safe after provider attempts
azooz2003-bit 2db126f
Close account deletion cleanup gaps
azooz2003-bit b55f23b
Record subscription state before deletion skips
azooz2003-bit b7e8e4a
Avoid stale auth during account deletion retry
azooz2003-bit fe4df74
Keep Stripe webhooks retryable for missing Stack users
azooz2003-bit a79d03a
Block delayed checkout writes during account deletion
azooz2003-bit c4e1de5
Skip stale Stripe metadata after account deletion
azooz2003-bit fffc650
Restore deletion metadata before destructive cleanup
azooz2003-bit 3a9c3d9
Bound account deletion identity cleanup
azooz2003-bit 402bfbd
Cancel deleting-account checkout completions
azooz2003-bit 46f719f
Close deletion cleanup retry gaps
azooz2003-bit e7aaf4d
Continue checkout cleanup after canceled subscriptions
azooz2003-bit 6c40a74
Treat Subrouter revoke attempts as destructive
azooz2003-bit b2833f5
Serialize account deletion with personal VM creation
azooz2003-bit 424c3b8
Preserve deletion state after SSH revoke cleanup
azooz2003-bit 871f805
Harden account deletion cleanup coverage
azooz2003-bit 1004394
Restrict account deletion to owned Stack teams
azooz2003-bit 463f904
Add deletion tombstone guards
azooz2003-bit f71a8db
Serialize checkout completion with account deletion
azooz2003-bit 9e6fa41
Cancel personal team billing during deletion
azooz2003-bit c3a49fc
Anonymize retained shared team VMs
azooz2003-bit 51825c9
Guard team checkout during account deletion
azooz2003-bit 728c545
Transfer retained team billing during deletion
azooz2003-bit aa2110c
Treat post-stack deletion failures as accepted
azooz2003-bit a924535
Serialize account deletion cleanup
azooz2003-bit ed30ccd
Fix deletion retry blockers
azooz2003-bit f7415c8
Handle pending account deletion safely
azooz2003-bit 80046dc
Move checkout entitlement sync after commit
azooz2003-bit e221420
Close account deletion edge cases
azooz2003-bit efec72f
Keep team checkout customers during deletion
azooz2003-bit 2d196e4
Keep account deletion leases fresh
azooz2003-bit 69f326f
Close account deletion VM cleanup gaps
azooz2003-bit 0bf7fb3
Keep incomplete account deletion retryable
azooz2003-bit dbbef35
Guard billing sync during account deletion
azooz2003-bit fdb9465
Skip tombstoned team billing webhooks
azooz2003-bit 0bf1784
Close account deletion billing races
azooz2003-bit 10bfed7
Close account deletion cleanup gaps
azooz2003-bit db70bbd
Synchronize account vault cleanup
azooz2003-bit d096099
Delete account vault upload tracking rows
azooz2003-bit 24f1db7
Block Base VM creation during account deletion
azooz2003-bit b19bc1e
Unwrap Base deletion block in DB test
azooz2003-bit c328efd
Handle terminal account deletion retries
azooz2003-bit 11bd876
Close account deletion retry blockers
azooz2003-bit 5d65ed8
Delete owned team Stripe rows during account deletion
azooz2003-bit 812d4b5
Fix deletion review state and support subject
azooz2003-bit 4fa4b4c
Page Stack teams during account deletion
azooz2003-bit a70b4db
Accept large non-paginated Stack teams
azooz2003-bit 2241674
Fail closed on ownerless team checkout completion
azooz2003-bit dd8a18c
Fail closed on ownerless team subscription webhooks
azooz2003-bit 15452d2
Serialize device registration with account deletion
azooz2003-bit a64c19f
Block account mutations before scope discovery
azooz2003-bit 4b0079d
Skip providerless VMs during deletion teardown
azooz2003-bit 5862c2e
Mark VM deletion destructive after provider destroy
azooz2003-bit d84a3df
Keep account deletion cleanup progressing
azooz2003-bit 3ff08ce
Separate account deletion VM blocks
azooz2003-bit 71b8c8f
Close account deletion cleanup gaps
azooz2003-bit 4da93ee
Merge remote-tracking branch 'origin/main' into feat-ios-account-dele…
azooz2003-bit 65327e9
Respect account deletion tombstone lease
azooz2003-bit 47f7ea5
Close account deletion route cleanup gaps
azooz2003-bit e957eae
Preserve legacy team checkout completion
azooz2003-bit 260fb26
Clear stale deletion auth lockouts
azooz2003-bit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
...CmuxAuthRuntime/Sources/CmuxAuthRuntime/Coordinator/AuthCoordinator+AccountDeletion.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| import Foundation | ||
|
|
||
| public enum AccountDeletionRequestError: Error, Equatable { | ||
| case invalidAPIBaseURL | ||
| case unauthorized | ||
| case stackDeleteIncomplete | ||
| /// The DELETE request reached the transport layer and timed out before a | ||
| /// definitive response. The backend may still complete account deletion, so | ||
| /// callers must treat the local session as no longer trustworthy. | ||
| case timedOut | ||
| case rejected(statusCode: Int) | ||
| case invalidResponse | ||
| } | ||
|
|
||
| typealias AccountDeletionRequestLoader = @Sendable (URLRequest) async throws -> (Data, URLResponse) | ||
|
|
||
| nonisolated private struct AccountDeletionErrorResponse: Decodable { | ||
| let error: String | ||
| } | ||
|
|
||
| struct AccountDeletionClient: Sendable { | ||
| private let apiBaseURL: String | ||
| private let requestTimeout: TimeInterval | ||
| private let load: AccountDeletionRequestLoader | ||
|
|
||
| init( | ||
| apiBaseURL: String, | ||
| requestTimeout: TimeInterval = 60, | ||
| load: @escaping AccountDeletionRequestLoader = { request in | ||
| try await URLSession.shared.data(for: request) | ||
| } | ||
| ) { | ||
| self.apiBaseURL = apiBaseURL | ||
| self.requestTimeout = requestTimeout | ||
| self.load = load | ||
| } | ||
|
|
||
| @concurrent | ||
| func deleteAccount(accessToken: String, refreshToken: String) async throws { | ||
| let trimmedBaseURL = apiBaseURL.hasSuffix("/") ? String(apiBaseURL.dropLast()) : apiBaseURL | ||
| guard let url = URL(string: trimmedBaseURL + "/api/account") else { | ||
| throw AccountDeletionRequestError.invalidAPIBaseURL | ||
| } | ||
|
|
||
| var request = URLRequest(url: url, timeoutInterval: requestTimeout) | ||
| request.httpMethod = "DELETE" | ||
| request.setValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization") | ||
| request.setValue(refreshToken, forHTTPHeaderField: "X-Stack-Refresh-Token") | ||
|
|
||
| let data: Data | ||
| let response: URLResponse | ||
| do { | ||
| (data, response) = try await load(request) | ||
| } catch let error as URLError where error.code == .timedOut { | ||
| throw AccountDeletionRequestError.timedOut | ||
| } | ||
| guard let httpResponse = response as? HTTPURLResponse else { | ||
| throw AccountDeletionRequestError.invalidResponse | ||
| } | ||
| switch httpResponse.statusCode { | ||
| case 200..<300: | ||
| return | ||
| case 401: | ||
| throw AccountDeletionRequestError.unauthorized | ||
| default: | ||
| if Self.isRetryablePartialDeletionError(Self.errorCode(in: data)) { | ||
| throw AccountDeletionRequestError.stackDeleteIncomplete | ||
| } | ||
| throw AccountDeletionRequestError.rejected(statusCode: httpResponse.statusCode) | ||
| } | ||
| } | ||
|
|
||
| private static func errorCode(in data: Data) -> String? { | ||
| try? JSONDecoder().decode(AccountDeletionErrorResponse.self, from: data).error | ||
| } | ||
|
|
||
| private static func isRetryablePartialDeletionError(_ code: String?) -> Bool { | ||
| code == "account_delete_retryable" || | ||
| code == "account_stack_delete_failed_after_data_delete" | ||
| } | ||
| } | ||
|
|
||
| extension AuthCoordinator { | ||
| /// Permanently deletes the current Stack account through cmux's backend. | ||
| /// | ||
| /// Callers clear local shell/auth state through their normal sign-out owner | ||
| /// after this succeeds so app-level teardown hooks run in the right order. | ||
| public func deleteAccount() async throws { | ||
| let apiBaseURL = apiBaseURL | ||
| let timeout = timeouts.network | ||
| let tokens = try await runTokenTouchingPhase(.accountDeletion, timeout: timeout) { | ||
| try await self.currentTokens() | ||
| } | ||
| try await AccountDeletionClient(apiBaseURL: apiBaseURL).deleteAccount( | ||
| accessToken: tokens.accessToken, | ||
| refreshToken: tokens.refreshToken | ||
| ) | ||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
Packages/Shared/CmuxAuthRuntime/Tests/CmuxAuthRuntimeTests/AccountDeletionClientTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import Foundation | ||
| import Testing | ||
| @testable import CmuxAuthRuntime | ||
|
|
||
| struct AccountDeletionClientTests { | ||
| @Test func deleteAccountSendsNativeAuthHeaders() async throws { | ||
| let recorder = RecordedAccountDeletionRequest() | ||
| let client = AccountDeletionClient(apiBaseURL: "https://cmux.test/base", requestTimeout: 12) { request in | ||
| await recorder.record(request) | ||
| return ( | ||
| Data(), | ||
| HTTPURLResponse( | ||
| url: request.url!, | ||
| statusCode: 204, | ||
| httpVersion: nil, | ||
| headerFields: nil | ||
| )! | ||
| ) | ||
| } | ||
|
|
||
| try await client.deleteAccount(accessToken: "access-token", refreshToken: "refresh-token") | ||
|
|
||
| let request = await recorder.request | ||
| #expect(request?.url?.absoluteString == "https://cmux.test/base/api/account") | ||
| #expect(request?.httpMethod == "DELETE") | ||
| #expect(request?.timeoutInterval == 12) | ||
| #expect(request?.value(forHTTPHeaderField: "Authorization") == "Bearer access-token") | ||
| #expect(request?.value(forHTTPHeaderField: "X-Stack-Refresh-Token") == "refresh-token") | ||
| } | ||
|
|
||
| @Test func deleteAccountMapsUnauthorizedResponse() async { | ||
| let client = AccountDeletionClient(apiBaseURL: "https://cmux.test") { request in | ||
| ( | ||
| Data(), | ||
| HTTPURLResponse( | ||
| url: request.url!, | ||
| statusCode: 401, | ||
| httpVersion: nil, | ||
| headerFields: nil | ||
| )! | ||
| ) | ||
| } | ||
|
|
||
| await #expect(throws: AccountDeletionRequestError.unauthorized) { | ||
| try await client.deleteAccount(accessToken: "access-token", refreshToken: "refresh-token") | ||
| } | ||
| } | ||
|
|
||
| @Test func deleteAccountMapsStackDeleteIncompleteResponse() async { | ||
| let client = AccountDeletionClient(apiBaseURL: "https://cmux.test") { request in | ||
| ( | ||
| Data(#"{"error":"account_delete_retryable"}"#.utf8), | ||
| HTTPURLResponse( | ||
| url: request.url!, | ||
| statusCode: 500, | ||
| httpVersion: nil, | ||
| headerFields: nil | ||
| )! | ||
| ) | ||
| } | ||
|
|
||
| await #expect(throws: AccountDeletionRequestError.stackDeleteIncomplete) { | ||
| try await client.deleteAccount(accessToken: "access-token", refreshToken: "refresh-token") | ||
| } | ||
| } | ||
|
|
||
| @Test func deleteAccountMapsLegacyPartialDeletionResponse() async { | ||
| let client = AccountDeletionClient(apiBaseURL: "https://cmux.test") { request in | ||
| ( | ||
| Data(#"{"error":"account_stack_delete_failed_after_data_delete"}"#.utf8), | ||
| HTTPURLResponse( | ||
| url: request.url!, | ||
| statusCode: 500, | ||
| httpVersion: nil, | ||
| headerFields: nil | ||
| )! | ||
| ) | ||
| } | ||
|
|
||
| await #expect(throws: AccountDeletionRequestError.stackDeleteIncomplete) { | ||
| try await client.deleteAccount(accessToken: "access-token", refreshToken: "refresh-token") | ||
| } | ||
| } | ||
|
|
||
| @Test func deleteAccountMapsTransportTimeout() async { | ||
| let client = AccountDeletionClient(apiBaseURL: "https://cmux.test") { _ in | ||
| throw URLError(.timedOut) | ||
| } | ||
|
|
||
| await #expect(throws: AccountDeletionRequestError.timedOut) { | ||
| try await client.deleteAccount(accessToken: "access-token", refreshToken: "refresh-token") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| actor RecordedAccountDeletionRequest { | ||
| private(set) var request: URLRequest? | ||
|
|
||
| func record(_ request: URLRequest) { | ||
| self.request = request | ||
| } | ||
| } |
163 changes: 163 additions & 0 deletions
163
Packages/iOS/CmuxMobileShellUI/Sources/CmuxMobileShellUI/MobileSettingsAccountSection.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| #if os(iOS) | ||
| import CmuxAuthRuntime | ||
| import CmuxMobileSupport | ||
| import SwiftUI | ||
|
|
||
| struct MobileSettingsAccountSection: View { | ||
| @Environment(AuthCoordinator.self) private var authManager | ||
| @Environment(\.dismiss) private var dismiss | ||
| let signOut: (() -> Void)? | ||
|
|
||
| @State private var showingDeleteAccountConfirmation = false | ||
| @State private var showingDeleteAccountFailure = false | ||
| @State private var deleteAccountFailureKind = DeleteAccountFailureKind.generic | ||
| @State private var deletingAccount = false | ||
| @State private var deleteAccountTask: Task<Void, Never>? | ||
|
|
||
| var body: some View { | ||
| Section { | ||
| LabeledContent { | ||
| Text(accountEmail) | ||
| .foregroundStyle(.secondary) | ||
| .textSelection(.enabled) | ||
| } label: { | ||
| Label(accountDisplayName, systemImage: "person.crop.circle") | ||
| } | ||
| .accessibilityIdentifier("MobileSettingsAccountRow") | ||
|
|
||
| if let signOut { | ||
| Button(role: .destructive) { | ||
| signOut() | ||
| dismiss() | ||
| } label: { | ||
| Label( | ||
| L10n.string("mobile.signOut", defaultValue: "Sign Out"), | ||
| systemImage: "rectangle.portrait.and.arrow.right" | ||
| ) | ||
| } | ||
| .accessibilityIdentifier("MobileSettingsSignOut") | ||
| } | ||
|
|
||
| Button(role: .destructive) { | ||
| showingDeleteAccountConfirmation = true | ||
| } label: { | ||
| Label( | ||
| deletingAccount | ||
| ? L10n.string("mobile.settings.deletingAccount", defaultValue: "Deleting Account...") | ||
| : L10n.string("mobile.settings.deleteAccount", defaultValue: "Delete Account"), | ||
| systemImage: deletingAccount ? "hourglass" : "trash" | ||
| ) | ||
| } | ||
| .disabled(deletingAccount) | ||
| .accessibilityIdentifier("MobileSettingsDeleteAccount") | ||
| } header: { | ||
| Text(L10n.string("mobile.settings.account", defaultValue: "Account")) | ||
| } footer: { | ||
| Text(L10n.string( | ||
| "mobile.settings.accountFooter", | ||
| defaultValue: "This device must be signed in to the same cmux account as the computer you pair with." | ||
| )) | ||
| } | ||
| .alert( | ||
| L10n.string("mobile.settings.deleteAccountTitle", defaultValue: "Delete Account?"), | ||
| isPresented: $showingDeleteAccountConfirmation | ||
| ) { | ||
| Button(L10n.string("mobile.settings.deleteAccountCancel", defaultValue: "Cancel"), role: .cancel) {} | ||
| Button( | ||
| L10n.string("mobile.settings.deleteAccountConfirm", defaultValue: "Delete Account"), | ||
| role: .destructive | ||
| ) { | ||
| deleteAccount() | ||
| } | ||
| } message: { | ||
| Text(L10n.string( | ||
| "mobile.settings.deleteAccountMessage", | ||
| defaultValue: "This permanently deletes your cmux account and cmux data. You will be signed out on this device." | ||
| )) | ||
| } | ||
| .alert( | ||
| L10n.string("mobile.settings.deleteAccountFailedTitle", defaultValue: "Couldn't Delete Account"), | ||
| isPresented: $showingDeleteAccountFailure | ||
| ) { | ||
| Button(L10n.string("mobile.settings.deleteAccountFailureOK", defaultValue: "OK"), role: .cancel) {} | ||
| } message: { | ||
| Text(deleteAccountFailureKind.localizedMessage) | ||
| } | ||
| } | ||
|
|
||
| private func deleteAccount() { | ||
| guard !deletingAccount, deleteAccountTask == nil else { return } | ||
| deletingAccount = true | ||
| deleteAccountTask = Task { | ||
| defer { | ||
| deleteAccountTask = nil | ||
| deletingAccount = false | ||
| } | ||
| do { | ||
| try await authManager.deleteAccount() | ||
| if let signOut { | ||
| signOut() | ||
| } else { | ||
| await authManager.signOut() | ||
| } | ||
| dismiss() | ||
| } catch { | ||
| if case AccountDeletionRequestError.stackDeleteIncomplete = error { | ||
| deleteAccountFailureKind = .stackDeleteIncomplete | ||
| } else if case AccountDeletionRequestError.timedOut = error { | ||
| if let signOut { | ||
| signOut() | ||
| } else { | ||
| await authManager.signOut() | ||
| } | ||
| dismiss() | ||
| return | ||
| } else if case AuthError.timedOut = error { | ||
| deleteAccountFailureKind = .timedOut | ||
| } else { | ||
| deleteAccountFailureKind = .generic | ||
| } | ||
| showingDeleteAccountFailure = true | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private var accountEmail: String { | ||
| let email = authManager.currentUser?.primaryEmail?.trimmingCharacters(in: .whitespacesAndNewlines) | ||
| if let email, !email.isEmpty { return email } | ||
| return L10n.string("mobile.settings.notSignedIn", defaultValue: "Not signed in") | ||
| } | ||
|
|
||
| private var accountDisplayName: String { | ||
| let name = authManager.currentUser?.displayName?.trimmingCharacters(in: .whitespacesAndNewlines) | ||
| if let name, !name.isEmpty { return name } | ||
| return L10n.string("mobile.settings.account", defaultValue: "Account") | ||
| } | ||
| } | ||
|
|
||
| private enum DeleteAccountFailureKind { | ||
| case generic | ||
| case stackDeleteIncomplete | ||
| case timedOut | ||
|
|
||
| var localizedMessage: String { | ||
| switch self { | ||
| case .generic: | ||
| return L10n.string( | ||
| "mobile.settings.deleteAccountFailedMessage", | ||
| defaultValue: "Try again later or contact support." | ||
| ) | ||
| case .stackDeleteIncomplete: | ||
| return L10n.string( | ||
| "mobile.settings.deleteAccountPartialFailureMessage", | ||
| defaultValue: "Your cmux data was deleted, but account sign-in cleanup did not finish. Try Delete Account again to complete deletion." | ||
| ) | ||
| case .timedOut: | ||
| return L10n.string( | ||
| "mobile.settings.deleteAccountTimedOutMessage", | ||
| defaultValue: "Account deletion timed out. Check your connection and try again." | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| #endif |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.