migrate the account lifecycle dialogs to the pds and chat clients

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Samuel Newman
2026-08-03 20:32:32 +03:00
parent cc295497fe
commit dc90f4ee37
4 changed files with 37 additions and 30 deletions
-6
View File
@@ -1099,12 +1099,6 @@
},
"typescript/no-misused-promises": {
"count": 2
},
"typescript/no-unsafe-call": {
"count": 2
},
"typescript/no-unsafe-member-access": {
"count": 2
}
},
"src/screens/Settings/components/CopyButton.tsx": {
@@ -7,8 +7,9 @@ import * as EmailValidator from 'email-validator'
import {cleanError, isNetworkError} from '#/lib/strings/errors'
import {checkAndFormatResetCode} from '#/lib/strings/password'
import {matchXrpcError} from '#/lib/xrpc-error'
import {logger} from '#/logger'
import {useAgent, useSession} from '#/state/session'
import {usePdsClient, useSession} from '#/state/session'
import {ErrorMessage} from '#/view/com/util/error/ErrorMessage'
import {android, atoms as a, web} from '#/alf'
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
@@ -17,6 +18,7 @@ import * as TextField from '#/components/forms/TextField'
import {Loader} from '#/components/Loader'
import {Text} from '#/components/Typography'
import {IS_NATIVE} from '#/env'
import {com} from '#/lexicons'
enum Stages {
RequestCode = 'RequestCode',
@@ -44,7 +46,7 @@ export function ChangePasswordDialog({
function Inner() {
const {_} = useLingui()
const {currentAccount} = useSession()
const agent = useAgent()
const client = usePdsClient()
const control = Dialog.useDialogContext()
const [stage, setStage] = useState(Stages.RequestCode)
@@ -85,7 +87,7 @@ function Inner() {
setError('')
setIsProcessing(true)
try {
await agent.com.atproto.server.requestPasswordReset({
await client.call(com.atproto.server.requestPasswordReset, {
email: currentAccount.email,
})
setStage(Stages.ChangePassword)
@@ -129,7 +131,7 @@ function Inner() {
setError('')
setIsProcessing(true)
try {
await agent.com.atproto.server.resetPassword({
await client.call(com.atproto.server.resetPassword, {
token: formattedCode,
password: newPassword,
})
@@ -141,7 +143,9 @@ function Inner() {
msg`Unable to contact your service. Please check your internet connection and try again.`,
),
)
} else if (e?.toString().includes('Token is invalid')) {
} else if (
matchXrpcError(e, com.atproto.server.resetPassword) === 'InvalidToken'
) {
setError(_(msg`This confirmation code is not valid. Please try again.`))
} else {
logger.error('Failed to set new password', {safeMessage: e})
@@ -5,7 +5,7 @@ import {useLingui} from '@lingui/react'
import {Trans} from '@lingui/react/macro'
import {logger} from '#/logger'
import {useAgent, useSessionApi} from '#/state/session'
import {usePdsClient, useSessionApi} from '#/state/session'
import {atoms as a, useTheme} from '#/alf'
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
import {type DialogOuterProps} from '#/components/Dialog'
@@ -14,6 +14,7 @@ import {CircleInfo_Stroke2_Corner0_Rounded as CircleInfo} from '#/components/ico
import {Loader} from '#/components/Loader'
import * as Prompt from '#/components/Prompt'
import {Text} from '#/components/Typography'
import {com} from '#/lexicons'
export function DeactivateAccountDialog({
control,
@@ -34,7 +35,7 @@ function DeactivateAccountDialogInner({
}) {
const t = useTheme()
const {_} = useLingui()
const agent = useAgent()
const client = usePdsClient()
const {logoutCurrentAccount} = useSessionApi()
const [pending, setPending] = useState(false)
const [error, setError] = useState<string | undefined>()
@@ -42,7 +43,7 @@ function DeactivateAccountDialogInner({
const handleDeactivate = useCallback(async () => {
try {
setPending(true)
await agent.com.atproto.server.deactivateAccount({})
await client.call(com.atproto.server.deactivateAccount, {})
control.close(() => {
logoutCurrentAccount('Deactivated')
})
@@ -66,7 +67,7 @@ function DeactivateAccountDialogInner({
} finally {
setPending(false)
}
}, [agent, control, logoutCurrentAccount, _, setPending])
}, [client, control, logoutCurrentAccount, _, setPending])
return (
<>
@@ -1,14 +1,19 @@
import {useCallback, useRef, useState} from 'react'
import {type TextInput, View} from 'react-native'
import {type DidString} from '@atproto/syntax'
import {msg} from '@lingui/core/macro'
import {useLingui} from '@lingui/react'
import {Trans} from '@lingui/react/macro'
import {DM_SERVICE_HEADERS} from '#/lib/constants'
import {useCleanError} from '#/lib/hooks/useCleanError'
import {sanitizeHandle} from '#/lib/strings/handles'
import {logger} from '#/logger'
import {useAgent, useSession, useSessionApi} from '#/state/session'
import {
useChatClient,
usePdsClient,
useSession,
useSessionApi,
} from '#/state/session'
import {atoms as a, useTheme} from '#/alf'
import {Admonition} from '#/components/Admonition'
import {type DialogOuterProps} from '#/components/Dialog'
@@ -24,6 +29,7 @@ import {Loader} from '#/components/Loader'
import * as Prompt from '#/components/Prompt'
import * as toast from '#/components/Toast'
import {Span, Text} from '#/components/Typography'
import {chat, com} from '#/lexicons'
import {resetToTab} from '#/Navigation'
const WHITESPACE_RE = /\s/gu
@@ -72,7 +78,8 @@ function DeleteAccountDialogInner({
const t = useTheme()
const {_} = useLingui()
const cleanError = useCleanError()
const agent = useAgent()
const client = usePdsClient()
const chatClient = useChatClient()
const {currentAccount} = useSession()
const {removeAccount} = useSessionApi()
@@ -89,7 +96,7 @@ function DeleteAccountDialogInner({
}
try {
setEmailState(EmailState.PENDING)
await agent.com.atproto.server.requestAccountDelete()
await client.call(com.atproto.server.requestAccountDelete)
setError('')
setEmailSentCount(prevCount => prevCount + 1)
setStep(Step.VERIFY_CODE)
@@ -103,7 +110,7 @@ function DeleteAccountDialogInner({
} finally {
setEmailState(EmailState.DEFAULT)
}
}, [agent, cleanError, emailState, setEmailState])
}, [client, cleanError, emailState, setEmailState])
const confirmDeletion = useCallback(async () => {
try {
@@ -112,15 +119,15 @@ function DeleteAccountDialogInner({
throw new Error('Invalid did')
}
const token = confirmCode.replace(WHITESPACE_RE, '')
// Inform chat service of intent to delete account.
const {success} = await agent.chat.bsky.actor.deleteAccount(undefined, {
headers: DM_SERVICE_HEADERS,
})
if (!success) {
throw new Error('Failed to inform chat service of account deletion')
}
await agent.com.atproto.server.deleteAccount({
did: currentAccount.did,
/*
* Inform chat service of intent to delete account. A non-2xx response
* throws, so reaching the next line means the chat service accepted it -
* the agent's `success` flag has no client-side equivalent.
*/
await chatClient.call(chat.bsky.actor.deleteAccount)
await client.call(com.atproto.server.deleteAccount, {
// the persisted account did is already resolved
did: currentAccount.did as DidString,
password,
token,
})
@@ -142,8 +149,9 @@ function DeleteAccountDialogInner({
}
}, [
_,
agent,
chatClient,
cleanError,
client,
confirmCode,
control,
currentAccount,