Account switcher: multi-account auth + Settings picker
Created by: jedmund
Summary
Adds support for saving multiple Pixiv accounts and switching between them from Settings or the signed-out screen.
-
Per-user keychain — each account's tokens stored at
pixiv.token.<userID>, with a separatepixiv.activeUserIDpointer. Legacy single-account entry migrates on first read; no user action required. -
Active-user model —
TokenStoretracks which account is current, loads its tokens on bootstrap, and exposesswitchAccount(to:)/removeAccount(userID:)/knownAccounts(). - Logout semantics — signing out clears the active pointer but leaves other saved accounts on disk. UI goes to the signed-out screen with an account picker.
-
Per-account bookmarks index — SwiftData configuration is already userID-scoped (
bookmarks-index-<userID>), so each account's index stays isolated across switches. No user data lost when switching. - Settings Accounts section — list with tap-to-switch (checkmark on active), swipe-to-remove, and "Add Account" that triggers OAuth and saves the new tokens alongside existing.
- Signed-out picker — when returning to signed-out with saved accounts, the CTA becomes a pickable list of those accounts plus a "Sign in with a different account" button.
Test plan
-
Fresh install with no prior auth: single sign-in screen, OAuth, lands at Home -
Sign in as account A → sign out via Settings → signed-out screen lists A -
Tap A on signed-out screen → lands back in as A without a web sheet -
From Settings, tap "Add Account" → Pixiv login web view → sign in as account B → lands as B -
From Settings → tap A in the Accounts section → sheet dismisses, app state updates to A, bookmarks index swaps to A's (different tag counts/thumbnails) -
Swipe to remove account B → it disappears from the Accounts list; if B was active, app goes to signed-out -
Remove all accounts → signed-out view falls back to the single-CTA first-run screen -
Upgrade path: install the previous single-account build, sign in, then install this build — existing account should appear with no re-auth required
Known limitation
Pixiv's web login remembers the last signed-in user. To add a SECOND account you have to sign out of Pixiv inside the web view first (bottom of the footer note in Settings calls this out). Every third-party client using the mobile OAuth flow hits the same constraint.