diff --git a/src/state/persisted/schema.ts b/src/state/persisted/schema.ts index 5b0fc2f2ce..67e082a95d 100644 --- a/src/state/persisted/schema.ts +++ b/src/state/persisted/schema.ts @@ -4,10 +4,7 @@ import {deviceLocales} from '#/platform/detection' const externalEmbedOptions = ['show', 'hide'] as const -/** - * A account persisted to storage. Stored in the `accounts[]` array. Contains - * base account info and access tokens. - */ +// only data needed for rendering account page const accountSchema = z.object({ service: z.string(), did: z.string(), @@ -20,26 +17,12 @@ const accountSchema = z.object({ }) export type PersistedAccount = z.infer -/** - * The current account. Stored in the `currentAccount` field. - * - * In previous versions, this included tokens and other info. Now, it's used - * only to reference the `did` field, and all other fields are marked as - * optional. They should be considered deprecated and not used, but are kept - * here for backwards compat. - */ -const currentAccountSchema = accountSchema.extend({ - service: z.string().optional(), - handle: z.string().optional(), -}) -export type PersistedCurrentAccount = z.infer - export const schema = z.object({ colorMode: z.enum(['system', 'light', 'dark']), darkTheme: z.enum(['dim', 'dark']).optional(), session: z.object({ accounts: z.array(accountSchema), - currentAccount: currentAccountSchema.optional(), + currentAccount: accountSchema.optional(), }), reminders: z.object({ lastEmailConfirm: z.string().optional(), diff --git a/src/state/session/index.tsx b/src/state/session/index.tsx index 653de62618..b88181ebda 100644 --- a/src/state/session/index.tsx +++ b/src/state/session/index.tsx @@ -581,24 +581,20 @@ export function Provider({children}: React.PropsWithChildren<{}>) { logger.debug(`session: persisted onUpdate`, {}) - const selectedAccount = session.accounts.find( - a => a.did === session.currentAccount?.did, - ) - - if (selectedAccount && selectedAccount.refreshJwt) { - if (selectedAccount.did !== state.currentAccount?.did) { + if (session.currentAccount && session.currentAccount.refreshJwt) { + if (session.currentAccount?.did !== state.currentAccount?.did) { logger.debug(`session: persisted onUpdate, switching accounts`, { from: { did: state.currentAccount?.did, handle: state.currentAccount?.handle, }, to: { - did: selectedAccount.did, - handle: selectedAccount.handle, + did: session.currentAccount.did, + handle: session.currentAccount.handle, }, }) - initSession(selectedAccount) + initSession(session.currentAccount) } else { logger.debug(`session: persisted onUpdate, updating session`, {}) @@ -608,9 +604,9 @@ export function Provider({children}: React.PropsWithChildren<{}>) { * already persisted, and we'll get a loop between tabs. */ // @ts-ignore we checked for `refreshJwt` above - __globalAgent.session = selectedAccount + __globalAgent.session = session.currentAccount } - } else if (!selectedAccount && state.currentAccount) { + } else if (!session.currentAccount && state.currentAccount) { logger.debug( `session: persisted onUpdate, logging out`, {}, @@ -629,7 +625,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) { setState(s => ({ ...s, accounts: session.accounts, - currentAccount: selectedAccount, + currentAccount: session.currentAccount, })) }) }, [state, setState, clearCurrentAccount, initSession])