add refreshSession to the session api and migrate its callers

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Samuel Newman
2026-08-04 00:55:02 +03:00
parent 7d8391aeb2
commit 483e79497b
10 changed files with 343 additions and 48 deletions
+22 -17
View File
@@ -7,10 +7,11 @@ import {Trans} from '@lingui/react/macro'
import {useQueryClient} from '@tanstack/react-query'
import {useAccountSwitcher} from '#/lib/hooks/useAccountSwitcher'
import {isErrorMaybeAppPasswordPermissions} from '#/lib/strings/errors'
import {logger} from '#/logger'
import {
type SessionAccount,
useAgent,
usePdsClient,
useSession,
useSessionApi,
} from '#/state/session'
@@ -25,6 +26,7 @@ import * as Layout from '#/components/Layout'
import {Loader} from '#/components/Loader'
import {Text} from '#/components/Typography'
import {IS_WEB} from '#/env'
import {com} from '#/lexicons'
const COL_WIDTH = 400
@@ -36,8 +38,8 @@ export function Deactivated() {
const {onPressSwitchAccount, pendingDid} = useAccountSwitcher()
const {setShowLoggedOut} = useLoggedOutViewControls()
const hasOtherAccounts = accounts.length > 1
const {logoutCurrentAccount} = useSessionApi()
const agent = useAgent()
const {logoutCurrentAccount, refreshSession} = useSessionApi()
const pdsClient = usePdsClient()
const [pending, setPending] = useState(false)
const [error, setError] = useState<string | undefined>()
const queryClient = useQueryClient()
@@ -70,21 +72,24 @@ export function Deactivated() {
const handleActivate = useCallback(async () => {
try {
setPending(true)
await agent.com.atproto.server.activateAccount()
await pdsClient.call(com.atproto.server.activateAccount)
await queryClient.resetQueries()
await agent.resumeSession(agent.session!)
await refreshSession()
} catch (e: any) {
switch (e.message) {
case 'Bad token scope':
setError(
_(
msg`You're signed in with an App Password. Please sign in with your main password to continue deactivating your account.`,
),
)
break
default:
setError(_(msg`Something went wrong, please try again`))
break
/*
* `activateAccount` declares no lexicon errors, so the app-password case
* arrives as an undeclared code plus a message. The shared helper matches
* both that and the plain-string form the old exact `e.message` switch
* relied on.
*/
if (isErrorMaybeAppPasswordPermissions(e)) {
setError(
_(
msg`You're signed in with an App Password. Please sign in with your main password to continue deactivating your account.`,
),
)
} else {
setError(_(msg`Something went wrong, please try again`))
}
logger.error(e, {
@@ -93,7 +98,7 @@ export function Deactivated() {
} finally {
setPending(false)
}
}, [_, agent, setPending, setError, queryClient])
}, [_, pdsClient, refreshSession, setPending, setError, queryClient])
return (
<View style={[a.util_screen_outer, a.flex_1]}>