force re-entering handle

This commit is contained in:
Samuel Newman
2025-04-22 16:33:33 +03:00
parent c864624543
commit faeacf8aa5
@@ -55,6 +55,7 @@ function Inner({
const [isProcessing, setIsProcessing] = useState(false) const [isProcessing, setIsProcessing] = useState(false)
const [confirmCode, setConfirmCode] = useState('') const [confirmCode, setConfirmCode] = useState('')
const [password, setPassword] = useState('') const [password, setPassword] = useState('')
const [handleInput, setHandleInput] = useState('')
const [error, setError] = useState('') const [error, setError] = useState('')
const onPressSendEmail = async () => { const onPressSendEmail = async () => {
@@ -74,18 +75,38 @@ function Inner({
throw new Error(`DeleteAccount modal: currentAccount.did is undefined`) throw new Error(`DeleteAccount modal: currentAccount.did is undefined`)
} }
if (!confirmCode) {
setError(_(msg`Please enter the confirmation code sent to your email.`))
return
}
if (!password) {
setError(_(msg`Please enter your password to confirm.`))
return
}
// Remove any @ symbol at the beginning and trim whitespace
const cleanedHandle = handleInput.replace(/^@/, '').trim()
if (!cleanedHandle) {
setError(_(msg`Please enter your handle to confirm deletion.`))
return
}
if (cleanedHandle.toLowerCase() !== currentAccount.handle.toLowerCase()) {
setError(_(msg`Handle doesn't match. Please enter your exact handle.`))
return
}
setError('') setError('')
setIsProcessing(true) setIsProcessing(true)
const token = confirmCode.replace(/\s/g, '') const token = confirmCode.replace(/\s/g, '')
try { try {
// inform chat service of intent to delete account // inform chat service of intent to delete account
const {success} = await agent.api.chat.bsky.actor.deleteAccount( const {success} = await agent.chat.bsky.actor.deleteAccount(undefined, {
undefined, headers: DM_SERVICE_HEADERS,
{ })
headers: DM_SERVICE_HEADERS,
},
)
if (!success) { if (!success) {
throw new Error('Failed to inform chat service of account deletion') throw new Error('Failed to inform chat service of account deletion')
} }
@@ -94,10 +115,11 @@ function Inner({
password, password,
token, token,
}) })
Toast.show(_(msg`Your account has been deleted`)) control.close(() => {
resetToTab('HomeTab') Toast.show(_(msg`Your account has been deleted`))
removeAccount(currentAccount) resetToTab('HomeTab')
control.close() removeAccount(currentAccount)
})
} catch (e: any) { } catch (e: any) {
setError(cleanError(e)) setError(cleanError(e))
} }
@@ -190,6 +212,21 @@ function Inner({
/> />
</TextField.Root> </TextField.Root>
</View> </View>
<View>
<TextField.LabelText>
<Trans>Handle of the account you want to delete</Trans>
</TextField.LabelText>
<TextField.Root>
<TextField.Input
label={_(msg`Your handle`)}
placeholder={currentAccount?.handle}
value={handleInput}
onChangeText={setHandleInput}
autoCapitalize="none"
autoCorrect={false}
/>
</TextField.Root>
</View>
</View> </View>
)} )}