From daaac0c676d18911541ced1058bed1b198ca2ac4 Mon Sep 17 00:00:00 2001 From: Rishi Balakrishnan Date: Tue, 2 Jun 2026 13:52:30 -0400 Subject: [PATCH] Merge pull request #101 from blacksky-algorithms/account-deactivation fix account reactivation flow --- eslint-suppressions.json | 35 ------- src/lib/strings/errors.ts | 8 +- src/locale/locales/en/messages.po | 130 +++++++++++++++++-------- src/screens/Deactivated.tsx | 136 +++++++++++++++++++++------ src/screens/Login/LoginForm.tsx | 12 ++- src/state/session/index.tsx | 2 + src/state/session/reducer.ts | 7 +- src/state/session/resolveForLogin.ts | 63 +++++++++++++ 8 files changed, 286 insertions(+), 107 deletions(-) create mode 100644 src/state/session/resolveForLogin.ts diff --git a/eslint-suppressions.json b/eslint-suppressions.json index 3e3fd5426..fe30f6451 100644 --- a/eslint-suppressions.json +++ b/eslint-suppressions.json @@ -134,21 +134,11 @@ "count": 1 } }, - "src/components/dialogs/DeviceLocationRequestDialog.tsx": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, "src/components/dialogs/EmailDialog/components/ResendEmailText.tsx": { "@typescript-eslint/no-explicit-any": { "count": 1 } }, - "src/components/dialogs/GifSelect.tsx": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, "src/components/dialogs/LanguageSelectDialog.tsx": { "@typescript-eslint/no-explicit-any": { "count": 1 @@ -229,11 +219,6 @@ "count": 3 } }, - "src/geolocation/service.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 2 - } - }, "src/lib/ScrollContext.tsx": { "@typescript-eslint/no-explicit-any": { "count": 3 @@ -364,11 +349,6 @@ "count": 1 } }, - "src/screens/Deactivated.tsx": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, "src/screens/Login/ChooseAccountForm.tsx": { "@typescript-eslint/no-explicit-any": { "count": 1 @@ -589,21 +569,6 @@ "count": 3 } }, - "src/view/com/lightbox/ImageViewing/@types/index.ts": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "src/view/com/lightbox/ImageViewing/components/ImageItem/ImageItem.android.tsx": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, - "src/view/com/lightbox/ImageViewing/index.tsx": { - "@typescript-eslint/no-explicit-any": { - "count": 1 - } - }, "src/view/com/lists/ListMembers.tsx": { "@typescript-eslint/no-explicit-any": { "count": 3 diff --git a/src/lib/strings/errors.ts b/src/lib/strings/errors.ts index 5171f94c3..65e6fec60 100644 --- a/src/lib/strings/errors.ts +++ b/src/lib/strings/errors.ts @@ -71,7 +71,13 @@ export function cleanError(str: any): string { return t`Account has been suspended` } if (str.includes('Account is deactivated')) { - return t`Account is deactivated` + return t`Your account is deactivated. If you recently moved to a new hosting provider, reactivate to complete the migration.` + } + if (str.includes('Account has been taken down')) { + return t`Account has been taken down` + } + if (str.includes('Account has been deleted')) { + return t`Account has been deleted` } if (str.includes('Profile not found')) { return t`Profile not found` diff --git a/src/locale/locales/en/messages.po b/src/locale/locales/en/messages.po index 481384824..3b2b24479 100644 --- a/src/locale/locales/en/messages.po +++ b/src/locale/locales/en/messages.po @@ -581,6 +581,11 @@ msgstr "" msgid "{userName}'s verifications" msgstr "" +#. placeholder {0}: currentAccount?.handle +#: src/screens/Deactivated.tsx:176 +msgid "@{0} is currently deactivated. If you recently moved to a new hosting provider, this is expected — reactivation is the last step to complete the migration." +msgstr "@{0} is currently deactivated. If you recently moved to a new hosting provider, this is expected — reactivation is the last step to complete the migration." + #. Indicates the number of additional profiles are in the Starter Pack e.g. +12 #: src/screens/Search/components/StarterPackCard.tsx:250 msgid "+{computedTotal}" @@ -755,7 +760,7 @@ msgid "Accessibility Settings" msgstr "" #: src/Navigation.tsx:425 -#: src/screens/Login/LoginForm.tsx:76 +#: src/screens/Login/LoginForm.tsx:86 #: src/screens/Settings/AccountSettings.tsx:69 #: src/screens/Settings/Settings.tsx:167 #: src/screens/Settings/Settings.tsx:170 @@ -783,13 +788,42 @@ msgctxt "toast" msgid "Account followed" msgstr "" +#: src/lib/strings/errors.ts:80 +msgid "Account has been deleted" +msgstr "Account has been deleted" + #: src/lib/strings/errors.ts:71 msgid "Account has been suspended" msgstr "" -#: src/lib/strings/errors.ts:74 -msgid "Account is deactivated" -msgstr "" +#: src/lib/strings/errors.ts:77 +msgid "Account has been taken down" +msgstr "Account has been taken down" + +#: src/screens/Deactivated.tsx:102 +msgid "Account is missing PDS information. Please sign in again." +msgstr "Account is missing PDS information. Please sign in again." + +#. placeholder {0}: source.handle +#: src/screens/Profile/components/ProfileStatusError.tsx:76 +msgid "Account is suspended by @{0}." +msgstr "Account is suspended by @{0}." + +#. placeholder {0}: source.handle +#. placeholder {1}: source.email +#: src/screens/Profile/components/ProfileStatusError.tsx:117 +msgid "Account is suspended by <0>@{0}, email <1>{1} to appeal." +msgstr "Account is suspended by <0>@{0}, email <1>{1} to appeal." + +#. placeholder {0}: source.handle +#: src/screens/Profile/components/ProfileStatusError.tsx:96 +msgid "Account is suspended by <0>@{0}. Click <1>here to submit an appeal." +msgstr "Account is suspended by <0>@{0}. Click <1>here to submit an appeal." + +#: src/screens/Profile/components/ProfileStatusError.tsx:67 +#: src/screens/Profile/components/ProfileStatusError.tsx:82 +msgid "Account is suspended." +msgstr "Account is suspended." #. placeholder {0}: source.handle #: src/screens/Profile/components/ProfileStatusError.tsx:76 @@ -914,7 +948,7 @@ msgid "Add a user to this list" msgstr "" #: src/components/dialogs/SwitchAccount.tsx:56 -#: src/screens/Deactivated.tsx:184 +#: src/screens/Deactivated.tsx:262 msgid "Add account" msgstr "" @@ -1667,8 +1701,8 @@ msgstr "" #: src/screens/Login/ChooseAccountForm.tsx:113 #: src/screens/Login/ForgotPasswordForm.tsx:124 #: src/screens/Login/ForgotPasswordForm.tsx:130 -#: src/screens/Login/LoginForm.tsx:106 -#: src/screens/Login/LoginForm.tsx:112 +#: src/screens/Login/LoginForm.tsx:116 +#: src/screens/Login/LoginForm.tsx:122 #: src/screens/Login/SetNewPasswordForm.tsx:170 #: src/screens/Login/SetNewPasswordForm.tsx:176 #: src/screens/Messages/components/ChatDisabled.tsx:148 @@ -2041,7 +2075,7 @@ msgstr "" #: src/features/liveNow/components/GoLiveDialog.tsx:248 #: src/features/liveNow/components/GoLiveDialog.tsx:254 #: src/lib/media/picker.tsx:38 -#: src/screens/Deactivated.tsx:150 +#: src/screens/Deactivated.tsx:228 #: src/screens/Messages/ConversationSettings/prompts.tsx:68 #: src/screens/Messages/ConversationSettings/prompts.tsx:92 #: src/screens/Profile/Header/EditProfileDialog.tsx:229 @@ -2081,7 +2115,7 @@ msgstr "Cancel account deletion" msgid "Cancel quote post" msgstr "" -#: src/screens/Deactivated.tsx:144 +#: src/screens/Deactivated.tsx:222 msgid "Cancel reactivation and sign out" msgstr "" @@ -2588,6 +2622,10 @@ msgstr "" msgid "Confirm delete account" msgstr "Confirm delete account" +#: src/screens/Deactivated.tsx:192 +msgid "Confirm with your account password" +msgstr "Confirm with your account password" + #: src/components/dialogs/EmailDialog/components/TokenField.tsx:38 #: src/screens/Settings/components/ChangePasswordDialog.tsx:187 #: src/screens/Settings/components/ChangePasswordDialog.tsx:191 @@ -2899,6 +2937,10 @@ msgstr "" msgid "Couldn’t load GIFs" msgstr "Couldn’t load GIFs" +#: src/screens/Deactivated.tsx:143 +msgid "Couldn't reactivate the account. Please try again." +msgstr "Couldn't reactivate the account. Please try again." + #: src/components/InternationalPhoneCodeSelect.tsx:77 msgid "Country code" msgstr "" @@ -3916,7 +3958,7 @@ msgstr "" msgid "Enter your email address" msgstr "" -#: src/screens/Login/LoginForm.tsx:97 +#: src/screens/Login/LoginForm.tsx:107 msgid "Enter your handle (e.g. alice.bsky.social)" msgstr "Enter your handle (e.g. alice.bsky.social)" @@ -5575,6 +5617,10 @@ msgstr "" msgid "Inbox zero!" msgstr "" +#: src/screens/Deactivated.tsx:137 +msgid "Incorrect password. Please try again." +msgstr "Incorrect password. Please try again." + #: src/screens/Settings/AIPreferencesSettings.tsx:222 msgid "Inference" msgstr "Inference" @@ -6216,8 +6262,8 @@ msgstr "" msgid "Logged-out visibility" msgstr "" -#: src/screens/Login/LoginForm.tsx:118 -#: src/screens/Login/LoginForm.tsx:125 +#: src/screens/Login/LoginForm.tsx:128 +#: src/screens/Login/LoginForm.tsx:135 msgid "Login" msgstr "Login" @@ -7531,11 +7577,11 @@ msgstr "Opens your hosting provider's account management page" msgid "Options:" msgstr "" -#: src/screens/Deactivated.tsx:192 +#: src/screens/Deactivated.tsx:270 msgid "Or, continue with another account." msgstr "" -#: src/screens/Deactivated.tsx:179 +#: src/screens/Deactivated.tsx:257 msgid "Or, sign in to one of your other accounts." msgstr "" @@ -7617,6 +7663,7 @@ msgstr "" msgid "Party GIFs" msgstr "Party GIFs" +#: src/screens/Deactivated.tsx:197 #: src/screens/Settings/AccountSettings.tsx:141 #: src/screens/Settings/AccountSettings.tsx:145 #: src/screens/Settings/AppPasswords.tsx:104 @@ -7924,7 +7971,7 @@ msgstr "Please enter your password:" msgid "Please enter your password." msgstr "Please enter your password." -#: src/screens/Login/LoginForm.tsx:42 +#: src/screens/Login/LoginForm.tsx:46 msgid "Please enter your username or handle" msgstr "Please enter your username or handle" @@ -8221,7 +8268,7 @@ msgstr "" msgid "Profile banner placeholder" msgstr "Profile banner placeholder" -#: src/lib/strings/errors.ts:77 +#: src/lib/strings/errors.ts:83 msgid "Profile not found" msgstr "" @@ -8363,10 +8410,18 @@ msgstr "" msgid "Reactions" msgstr "Reactions" -#: src/screens/Deactivated.tsx:133 +#: src/screens/Deactivated.tsx:217 +msgid "Reactivate my account" +msgstr "Reactivate my account" + +#: src/screens/Deactivated.tsx:210 msgid "Reactivate your account" msgstr "" +#: src/screens/Deactivated.tsx:183 +msgid "Reactivating will restore visibility of your profile and posts to other users." +msgstr "Reactivating will restore visibility of your profile and posts to other users." + #. placeholder {0}: item.moreReplies #: src/screens/PostThread/components/ThreadItemReadMore.tsx:93 msgid "Read {0, plural, one {# more reply} other {# more replies}}" @@ -9891,7 +9946,7 @@ msgstr "" #: src/screens/Hashtag.tsx:228 #: src/screens/Login/index.tsx:119 #: src/screens/Login/index.tsx:133 -#: src/screens/Login/LoginForm.tsx:73 +#: src/screens/Login/LoginForm.tsx:83 #: src/screens/Search/SearchResults.tsx:317 #: src/view/com/auth/SplashScreen.tsx:118 #: src/view/com/auth/SplashScreen.tsx:124 @@ -9923,8 +9978,8 @@ msgstr "Sign in failed. Please try again." msgid "Sign in is taking too long. Please try again." msgstr "Sign in is taking too long. Please try again." -#: src/screens/Deactivated.tsx:195 -#: src/screens/Deactivated.tsx:201 +#: src/screens/Deactivated.tsx:273 +#: src/screens/Deactivated.tsx:279 msgid "Sign in or create an account" msgstr "" @@ -10088,7 +10143,6 @@ msgid "Something went wrong" msgstr "" #: src/components/moderation/ReportDialog/index.tsx:291 -#: src/screens/Deactivated.tsx:86 #: src/screens/Settings/components/DeactivateAccountDialog.tsx:85 #: src/view/screens/Storybook/Admonitions.tsx:56 msgid "Something went wrong, please try again" @@ -10223,7 +10277,7 @@ msgstr "" msgid "Starter Packs let you share your favorite feeds and people with your friends." msgstr "" -#: src/screens/Login/LoginForm.tsx:119 +#: src/screens/Login/LoginForm.tsx:129 msgid "Starts the sign-in process" msgstr "Starts the sign-in process" @@ -11171,6 +11225,7 @@ msgid "Toggles the sound" msgstr "" #: src/components/contacts/screens/VerifyNumber.tsx:123 +#: src/screens/Deactivated.tsx:140 msgid "Too many attempts. Please wait a few minutes and try again." msgstr "" @@ -11279,6 +11334,10 @@ msgstr "" msgid "Two-factor authentication (2FA)" msgstr "" +#: src/screens/Deactivated.tsx:130 +msgid "Two-factor authentication is required to reactivate. Please disable 2FA temporarily, or contact support." +msgstr "Two-factor authentication is required to reactivate. Please disable 2FA temporarily, or contact support." + #: src/screens/Messages/components/MessageInput.tsx:174 msgid "Type your message here" msgstr "" @@ -11297,9 +11356,10 @@ msgstr "" msgid "Unable to contact your service. Please check your internet connection and try again." msgstr "" +#: src/screens/Deactivated.tsx:121 #: src/screens/Login/ForgotPasswordForm.tsx:69 #: src/screens/Login/index.tsx:92 -#: src/screens/Login/LoginForm.tsx:62 +#: src/screens/Login/LoginForm.tsx:72 #: src/screens/Login/SetNewPasswordForm.tsx:83 #: src/screens/Signup/index.tsx:89 msgid "Unable to contact your service. Please check your Internet connection." @@ -11309,7 +11369,7 @@ msgstr "" msgid "Unable to delete" msgstr "" -#: src/lib/strings/errors.ts:80 +#: src/lib/strings/errors.ts:86 msgid "Unable to resolve handle" msgstr "" @@ -11769,7 +11829,7 @@ msgstr "Username must be at least 3 characters" msgid "Username must only contain letters (a-z), numbers, and hyphens" msgstr "" -#: src/screens/Login/LoginForm.tsx:83 +#: src/screens/Login/LoginForm.tsx:93 msgid "Username or handle" msgstr "Username or handle" @@ -12256,7 +12316,7 @@ msgstr "" msgid "We're sorry! You can only subscribe to twenty labelers, and you've reached your limit of twenty." msgstr "" -#: src/screens/Deactivated.tsx:117 +#: src/screens/Deactivated.tsx:173 msgid "Welcome back!" msgstr "" @@ -12415,10 +12475,6 @@ msgstr "" msgid "Yes, hide" msgstr "" -#: src/screens/Deactivated.tsx:139 -msgid "Yes, reactivate my account" -msgstr "" - #: src/components/dms/DateDivider.tsx:45 msgid "Yesterday" msgstr "" @@ -12534,10 +12590,6 @@ msgstr "" msgid "You can only select one video at a time." msgstr "" -#: src/screens/Deactivated.tsx:125 -msgid "You can reactivate your account to continue logging in. Your profile and posts will be visible to other users." -msgstr "" - #. Error message for maximum number of images that can be selected to add to a post, currently 4 but may change. #: src/view/com/composer/SelectMediaButton.tsx:417 msgid "You can select up to {MAX_IMAGES, plural, other {# images}} in total." @@ -12731,11 +12783,6 @@ msgstr "" msgid "You need to verify your email address before you can enable email 2FA." msgstr "" -#. placeholder {0}: currentAccount?.handle -#: src/screens/Deactivated.tsx:120 -msgid "You previously deactivated @{0}." -msgstr "" - #: src/screens/Settings/Settings.tsx:410 msgid "You probably want to restart the app now." msgstr "" @@ -12815,7 +12862,6 @@ msgstr "" msgid "You're in line" msgstr "" -#: src/screens/Deactivated.tsx:81 #: src/screens/Settings/components/DeactivateAccountDialog.tsx:77 msgid "You're signed in with an App Password. Please sign in with your main password to continue deactivating your account." msgstr "" @@ -12885,6 +12931,10 @@ msgstr "" msgid "Your account has been suspended" msgstr "" +#: src/lib/strings/errors.ts:74 +msgid "Your account is deactivated. If you recently moved to a new hosting provider, reactivate to complete the migration." +msgstr "Your account is deactivated. If you recently moved to a new hosting provider, reactivate to complete the migration." + #: src/view/com/composer/state/video.ts:430 msgid "Your account is not yet old enough to upload videos. Please try again later." msgstr "" diff --git a/src/screens/Deactivated.tsx b/src/screens/Deactivated.tsx index 24d6cd90a..25afbcaf0 100644 --- a/src/screens/Deactivated.tsx +++ b/src/screens/Deactivated.tsx @@ -1,31 +1,59 @@ import {useCallback, useState} from 'react' import {View} from 'react-native' import {useSafeAreaInsets} from 'react-native-safe-area-context' +import {AtpAgent, XRPCError} from '@atproto/api' import {msg} from '@lingui/core/macro' import {useLingui} from '@lingui/react' import {Trans} from '@lingui/react/macro' import {useQueryClient} from '@tanstack/react-query' import {useAccountSwitcher} from '#/lib/hooks/useAccountSwitcher' +import {isNetworkError} from '#/lib/strings/errors' import {logger} from '#/logger' -import { - type SessionAccount, - useAgent, - useSession, - useSessionApi, -} from '#/state/session' +import {type SessionAccount, useSession, useSessionApi} from '#/state/session' import {useLoggedOutViewControls} from '#/state/shell/logged-out' import {Logo} from '#/view/icons/Logo' import {atoms as a, useTheme} from '#/alf' import {AccountList} from '#/components/AccountList' import {Button, ButtonIcon, ButtonText} from '#/components/Button' import {Divider} from '#/components/Divider' +import * as TextField from '#/components/forms/TextField' import {CircleInfo_Stroke2_Corner0_Rounded as CircleInfo} from '#/components/icons/CircleInfo' +import {Lock_Stroke2_Corner0_Rounded as Lock} from '#/components/icons/Lock' import * as Layout from '#/components/Layout' import {Loader} from '#/components/Loader' import {Text} from '#/components/Typography' import {IS_WEB} from '#/env' +async function reactivateWithPassword({ + pdsUrl, + identifier, + password, +}: { + pdsUrl: string + identifier: string + password: string +}) { + const agent = new AtpAgent({service: pdsUrl}) + await agent.login({identifier, password}) + try { + try { + await agent.com.atproto.server.activateAccount() + } catch (e) { + // On retry after a partial success, the account may already be active. + // Treat that as a successful no-op so the user isn't stuck. + if (e instanceof XRPCError && e.error === 'InvalidRequest') return + throw e + } + } finally { + try { + await agent.logout() + } catch { + // best-effort cleanup; the throwaway session expires anyway + } + } +} + const COL_WIDTH = 400 export function Deactivated() { @@ -36,9 +64,9 @@ export function Deactivated() { const {onPressSwitchAccount, pendingDid} = useAccountSwitcher() const {setShowLoggedOut} = useLoggedOutViewControls() const hasOtherAccounts = accounts.length > 1 - const {logoutCurrentAccount} = useSessionApi() - const agent = useAgent() + const {logoutCurrentAccount, partialRefreshSession} = useSessionApi() const [pending, setPending] = useState(false) + const [password, setPassword] = useState('') const [error, setError] = useState() const queryClient = useQueryClient() @@ -68,32 +96,60 @@ export function Deactivated() { }, [logoutCurrentAccount]) const handleActivate = useCallback(async () => { + if (!password.trim()) return + if (!currentAccount?.pdsUrl || !currentAccount.handle) { + setError( + _(msg`Account is missing PDS information. Please sign in again.`), + ) + return + } + setError(undefined) + setPending(true) try { - setPending(true) - await agent.com.atproto.server.activateAccount() + await reactivateWithPassword({ + pdsUrl: currentAccount.pdsUrl, + identifier: currentAccount.handle, + password, + }) + await partialRefreshSession() await queryClient.resetQueries() - await agent.resumeSession(agent.session!) - } 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 + setPassword('') + } catch (e: unknown) { + if (isNetworkError(e)) { + setError( + _( + msg`Unable to contact your service. Please check your Internet connection.`, + ), + ) + } else if ( + e instanceof XRPCError && + e.error === 'AuthFactorTokenRequired' + ) { + setError( + _( + msg`Two-factor authentication is required to reactivate. Please disable 2FA temporarily, or contact support.`, + ), + ) + } else if ( + e instanceof XRPCError && + (e.status === 401 || e.error === 'AuthenticationRequired') + ) { + setError(_(msg`Incorrect password. Please try again.`)) + } else if (e instanceof XRPCError && e.status === 429) { + setError( + _(msg`Too many attempts. Please wait a few minutes and try again.`), + ) + } else { + setError(_(msg`Couldn't reactivate the account. Please try again.`)) } - logger.error(e, { + logger.error(e instanceof Error ? e : String(e), { message: 'Failed to activate account', }) } finally { setPending(false) } - }, [_, agent, setPending, setError, queryClient]) + }, [_, currentAccount, password, queryClient, partialRefreshSession]) return ( @@ -118,25 +174,47 @@ export function Deactivated() { - You previously deactivated @{currentAccount?.handle}. + @{currentAccount?.handle} is currently deactivated. If you + recently moved to a new hosting provider, this is expected — + reactivation is the last step to complete the migration. - You can reactivate your account to continue logging in. Your - profile and posts will be visible to other users. + Reactivating will restore visibility of your profile and posts + to other users. + + + Confirm with your account password + + + + + + diff --git a/src/screens/Login/LoginForm.tsx b/src/screens/Login/LoginForm.tsx index 8a55940d6..49473bfdf 100644 --- a/src/screens/Login/LoginForm.tsx +++ b/src/screens/Login/LoginForm.tsx @@ -7,6 +7,10 @@ import {Trans} from '@lingui/react/macro' import {cleanError, isNetworkError} from '#/lib/strings/errors' import {logger} from '#/logger' import {getWebOAuthClient} from '#/state/session/oauth-web-client' +import { + isHandleResolutionError, + resolveDeactivatedHandle, +} from '#/state/session/resolveForLogin' import {atoms as a} from '#/alf' import {Button, ButtonIcon, ButtonText} from '#/components/Button' import {FormError} from '#/components/forms/FormError' @@ -47,7 +51,13 @@ export const LoginForm = ({ try { const client = getWebOAuthClient() - await client.signIn(identifier) + try { + await client.signIn(identifier) + } catch (e) { + if (!isHandleResolutionError(e)) throw e + const did = await resolveDeactivatedHandle(identifier) + await client.signIn(did) + } // Browser will redirect to authorization server } catch (e: any) { const errMsg = e.toString() diff --git a/src/state/session/index.tsx b/src/state/session/index.tsx index 64465674a..7ce99d390 100644 --- a/src/state/session/index.tsx +++ b/src/state/session/index.tsx @@ -313,6 +313,8 @@ export function Provider({children}: React.PropsWithChildren<{}>) { patch: { emailConfirmed: data.emailConfirmed, emailAuthFactor: data.emailAuthFactor, + active: data.active, + status: data.status, }, }) }, [store, state, cancelPendingTask]) diff --git a/src/state/session/reducer.ts b/src/state/session/reducer.ts index 9e2415be8..f02e3e486 100644 --- a/src/state/session/reducer.ts +++ b/src/state/session/reducer.ts @@ -58,7 +58,10 @@ export type Action = | { type: 'partial-refresh-session' accountDid: string - patch: Pick + patch: Pick< + SessionAccount, + 'emailConfirmed' | 'emailAuthFactor' | 'active' | 'status' + > } function createPublicAgentState(): AgentState { @@ -257,6 +260,8 @@ let reducer = (state: State, action: Action): State => { ...a, emailConfirmed: patch.emailConfirmed ?? a.emailConfirmed, emailAuthFactor: patch.emailAuthFactor ?? a.emailAuthFactor, + active: patch.active, + status: patch.status, } } return a diff --git a/src/state/session/resolveForLogin.ts b/src/state/session/resolveForLogin.ts new file mode 100644 index 000000000..30b0866c2 --- /dev/null +++ b/src/state/session/resolveForLogin.ts @@ -0,0 +1,63 @@ +import {AtpAgent, XRPCError} from '@atproto/api' + +import {BSKY_SERVICE, PUBLIC_BSKY_SERVICE} from '#/lib/constants' +import {isNetworkError} from '#/lib/strings/errors' + +export function isHandleResolutionError(e: unknown): boolean { + if (e && typeof e === 'object' && 'name' in e) { + const name = (e as {name?: unknown}).name + if (name === 'IdentityResolverError' || name === 'HandleResolverError') { + return true + } + } + const s = String(e) + return ( + s.includes('Unable to resolve handle') || + s.includes('does not resolve to a DID') || + s.includes('Failed to resolve identity') + ) +} + +export async function resolveDeactivatedHandle( + identifier: string, +): Promise { + if (identifier.startsWith('did:')) { + return identifier + } + const appview = new AtpAgent({service: PUBLIC_BSKY_SERVICE}) + let did: string + try { + const res = await appview.com.atproto.identity.resolveHandle({ + handle: identifier, + }) + did = res.data.did + } catch (e) { + if (isNetworkError(e)) throw e + throw new Error('Unable to resolve handle') + } + + const pds = new AtpAgent({service: BSKY_SERVICE}) + let active: boolean | undefined + let status: string | undefined + try { + const res = await pds.com.atproto.sync.getRepoStatus({did}) + active = res.data.active + status = res.data.status + } catch (e) { + if (e instanceof XRPCError && e.status === 404) { + return did + } + if (isNetworkError(e)) throw e + throw new Error('Unable to verify account status') + } + if (active || status === 'deactivated') { + return did + } + if (status === 'takendown') { + throw new Error('Account has been taken down') + } + if (status === 'suspended') { + throw new Error('Account has been suspended') + } + throw new Error('Unable to verify account status') +} -- knotmirror 0.0.1