feat(mobile): switch between signed-in T3 accounts - #1
Draft
rachelagent[bot] wants to merge 5 commits into
Draft
rachelagent[bot] wants to merge 5 commits into
rachelagent[bot] wants to merge 5 commits into
Conversation
Clerk multi-session lets the native profile view add and switch accounts. Move the account transition logic out of CloudAuthBridge into a tested controller so a direct A to B switch revokes A before B activates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Switching accounts used to act like a sign-out followed by a sign-in: the previous account's relay environments were dropped and T3 Connect onboarding ran again on every switch. Now each transition saves the outgoing account's relay environments while it stays signed in. Switching back reconnects them and restores drafts without onboarding. Onboarding only appears for an account this device has no saved record for, and sign-out forgets the account's saved environments. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- Bind each account's relay token reader to its own Clerk session, so cleanup after a switch unregisters the previous account's push device rather than the new one's. - Save an account's environment list before removing its environments, and never overwrite a saved list with an empty registry. A retried cleanup or an account skipped by rapid switches keeps its list. - Finish installing an account once its drafts are restored, even if a newer switch arrives, so the next cleanup archives everything it restored. - Delete a saved list once it has been restored, and resume a restore interrupted by the app closing. - Forget saved environments as soon as an inactive account signs out. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Cleanup targeted the last observed account, which is not always the account whose data is on the device. Track the installed account (and its token reader) instead, read from the drafts' owner on a cold start: - A failed cleanup leaves its account installed, so the next switch retries it rather than cleaning a skipped account's empty state. - Leaving an installed account always saves its list, including an empty one, so returning to it never re-onboards. An existing saved list is kept, since after an interrupted cleanup or restore it is the complete one. - The onboarding decision is made once at install and carried to activation, so a repeated Clerk session cannot re-request it. - Every account change clears a pending onboarding request. - Pending Clerk sessions count as signed in and keep their saved lists. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- Read the signed-in accounts when a change is observed, not when its cleanup runs, so signing straight back in cannot undo a sign-out and bring the old environments back. - Skip onboarding only before the first account change of the process (a cold start), so a session Clerk repeats before the new account installs still onboards it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Thread transfer impact
This comment will update automatically after the next completed run. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Mobile users with more than one T3 Connect account have to sign out and sign back in to move between them. Once Clerk multi-session is enabled on the instance, Clerk's native profile view (already used for Settings → T3 Account) shows Add account and Switch account on both iOS and Android. We don't need a custom switcher.
Before this PR, a switch from account A directly to B was a corner case.
CloudAuthBridgehandled it inside one untested effect. With multi-session it becomes the main path, so the logic now lives incloudAccountSync.ts, a small controller with tests.CloudAuthBridgefeeds it the current Clerk session and the set of signed-in accounts.The controller tracks the installed account: whose drafts and relay environments are on the device. When the user switches from A to B, it:
Signing out forgets that account's saved environments, including an account that isn't active. Signing out of one account while another stays signed in falls through to the remaining account, which reconnects its saved environments.
Each account's relay token reader is bound to its own Clerk session. That way the cleanup that runs after a switch unregisters the previous account's push device, not the new one's.
Races and crashes fail safe:
One account is active at a time. Keeping every account connected at once is a later PR.
Stacked on pingdotgg#2829's branch (
t3code/codex-turn-mapping). Multi-session is not yet enabled on the production Clerk instance. Until it is, the native view hides the new rows and behavior is unchanged.Testing
vp test run src/features/cloudinapps/mobile: 47 passed. ThecloudAccountSynctests cover:tsc --noEmitfor mobile, plusvp linton the changed files: clean.Recording
One scripted take:
Idle stretches are trimmed.
account-switching.mp4
Screenshots
Captured on an iOS 27 simulator running this branch. A local mitmproxy addon stands in for Clerk multi-session and the T3 Connect relay. Each account has its own relay environments, backed by real local T3 servers. "Alpha MacBook" is listed but has no server behind it.
1. Sign in as alpha: a new account, so onboarding lists its environments
2. Add bravo: alpha's environments are disconnected and saved, bravo onboards
3. Switch back to alpha: Alpha Studio reconnects, no onboarding
4. Sign out of alpha: the app falls through to bravo, whose environment reconnects
Opus 5.5 via Claude Code in T3 Code.
🤖 Generated with Claude Code