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