@@ -70,6 +70,7 @@ type Model struct {
7070 authService auth.Auth
7171 syncer powersync.Syncer
7272 services api.APIServices
73+ prefs preferences.Preferences
7374
7475 // Runtime (created after account selection / onboarding)
7576 db sqlite.DB
@@ -142,6 +143,7 @@ func New(
142143 authService : authService ,
143144 syncer : syncer ,
144145 services : services ,
146+ prefs : prefs ,
145147 statusBar : statusbar .New (theme , syncer , cfg .APIEndpoint ),
146148 toast : toast .New (theme ),
147149 keyBar : keybar .New (theme , scope ),
@@ -688,3 +690,41 @@ func (m *Model) shutdown() {
688690 m .db .Close ()
689691 }
690692}
693+
694+ // switchOrganization clears org preference (cascades to account and workspace)
695+ // and re-enters onboarding. Onboarding will prompt for all choices.
696+ func (m * Model ) switchOrganization () tea.Cmd {
697+ m .scope .Info ("switching organization" )
698+ _ = m .prefs .ClearDefaultOrgID ()
699+ return m .restartOnboarding ()
700+ }
701+
702+ // switchAccount clears account preference (cascades to workspace) and
703+ // re-enters onboarding. The saved org auto-selects, then prompts for account.
704+ func (m * Model ) switchAccount () tea.Cmd {
705+ m .scope .Info ("switching account" )
706+ _ = m .prefs .ClearDefaultAccountID ()
707+ return m .restartOnboarding ()
708+ }
709+
710+ // restartOnboarding tears down the current session and re-enters onboarding
711+ // at the org selection step. Onboarding auto-selects any saved preferences
712+ // and prompts for anything that was cleared.
713+ func (m * Model ) restartOnboarding () tea.Cmd {
714+ m .shutdown ()
715+
716+ m .db = nil
717+ m .uploader = nil
718+ m .chatClient = nil
719+ m .toolRegistry = nil
720+ m .chat = nil
721+
722+ m .statusBar = statusbar .New (m .theme , m .syncer , m .cfg .APIEndpoint )
723+ m .windowTitle = ""
724+
725+ m .onboarding = onboarding .New (m .ctx , m .theme , m .services , m .prefs , m .authService , m .syncer , m .scope )
726+ m .state = stateOnboarding
727+ m .updateLayout ()
728+
729+ return m .onboarding .StartFromOrgSelect ()
730+ }
0 commit comments