Replace updateCurrentAccount() with refreshSession() (#3910)
Replace updateCurrentAccount() with resumeSession()
This commit is contained in:
parent
f62b0458a7
commit
0c6bf276dd
9 changed files with 15 additions and 257 deletions
|
@ -4,7 +4,7 @@ import {msg, Trans} from '@lingui/macro'
|
|||
import {useLingui} from '@lingui/react'
|
||||
|
||||
import {useModalControls} from '#/state/modals'
|
||||
import {useAgent, useSession, useSessionApi} from '#/state/session'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
import {usePalette} from 'lib/hooks/usePalette'
|
||||
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
||||
import {cleanError} from 'lib/strings/errors'
|
||||
|
@ -28,7 +28,6 @@ export function Component() {
|
|||
const pal = usePalette('default')
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const {updateCurrentAccount} = useSessionApi()
|
||||
const {_} = useLingui()
|
||||
const [stage, setStage] = useState<Stages>(Stages.InputEmail)
|
||||
const [email, setEmail] = useState<string>(currentAccount?.email || '')
|
||||
|
@ -51,10 +50,7 @@ export function Component() {
|
|||
setStage(Stages.ConfirmCode)
|
||||
} else {
|
||||
await getAgent().com.atproto.server.updateEmail({email: email.trim()})
|
||||
updateCurrentAccount({
|
||||
email: email.trim(),
|
||||
emailConfirmed: false,
|
||||
})
|
||||
await getAgent().resumeSession(getAgent().session!)
|
||||
Toast.show(_(msg`Email updated`))
|
||||
setStage(Stages.Done)
|
||||
}
|
||||
|
@ -83,10 +79,7 @@ export function Component() {
|
|||
email: email.trim(),
|
||||
token: confirmationCode.trim(),
|
||||
})
|
||||
updateCurrentAccount({
|
||||
email: email.trim(),
|
||||
emailConfirmed: false,
|
||||
})
|
||||
await getAgent().resumeSession(getAgent().session!)
|
||||
Toast.show(_(msg`Email updated`))
|
||||
setStage(Stages.Done)
|
||||
} catch (e) {
|
||||
|
|
|
@ -15,12 +15,7 @@ import {logger} from '#/logger'
|
|||
import {useModalControls} from '#/state/modals'
|
||||
import {useFetchDid, useUpdateHandleMutation} from '#/state/queries/handle'
|
||||
import {useServiceQuery} from '#/state/queries/service'
|
||||
import {
|
||||
SessionAccount,
|
||||
useAgent,
|
||||
useSession,
|
||||
useSessionApi,
|
||||
} from '#/state/session'
|
||||
import {SessionAccount, useAgent, useSession} from '#/state/session'
|
||||
import {useAnalytics} from 'lib/analytics/analytics'
|
||||
import {usePalette} from 'lib/hooks/usePalette'
|
||||
import {cleanError} from 'lib/strings/errors'
|
||||
|
@ -73,10 +68,10 @@ export function Inner({
|
|||
const {_} = useLingui()
|
||||
const pal = usePalette('default')
|
||||
const {track} = useAnalytics()
|
||||
const {updateCurrentAccount} = useSessionApi()
|
||||
const {closeModal} = useModalControls()
|
||||
const {mutateAsync: updateHandle, isPending: isUpdateHandlePending} =
|
||||
useUpdateHandleMutation()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
const [error, setError] = useState<string>('')
|
||||
|
||||
|
@ -116,9 +111,7 @@ export function Inner({
|
|||
await updateHandle({
|
||||
handle: newHandle,
|
||||
})
|
||||
updateCurrentAccount({
|
||||
handle: newHandle,
|
||||
})
|
||||
await getAgent().resumeSession(getAgent().session!)
|
||||
closeModal()
|
||||
onChanged()
|
||||
} catch (err: any) {
|
||||
|
@ -134,9 +127,9 @@ export function Inner({
|
|||
onChanged,
|
||||
track,
|
||||
closeModal,
|
||||
updateCurrentAccount,
|
||||
updateHandle,
|
||||
serviceInfo,
|
||||
getAgent,
|
||||
])
|
||||
|
||||
// rendering
|
||||
|
|
|
@ -13,7 +13,7 @@ import {useLingui} from '@lingui/react'
|
|||
|
||||
import {logger} from '#/logger'
|
||||
import {useModalControls} from '#/state/modals'
|
||||
import {useAgent, useSession, useSessionApi} from '#/state/session'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
import {usePalette} from 'lib/hooks/usePalette'
|
||||
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
||||
import {cleanError} from 'lib/strings/errors'
|
||||
|
@ -43,7 +43,6 @@ export function Component({
|
|||
const pal = usePalette('default')
|
||||
const {getAgent} = useAgent()
|
||||
const {currentAccount} = useSession()
|
||||
const {updateCurrentAccount} = useSessionApi()
|
||||
const {_} = useLingui()
|
||||
const [stage, setStage] = useState<Stages>(
|
||||
showReminder ? Stages.Reminder : Stages.Email,
|
||||
|
@ -82,7 +81,7 @@ export function Component({
|
|||
email: (currentAccount?.email || '').trim(),
|
||||
token: confirmationCode.trim(),
|
||||
})
|
||||
updateCurrentAccount({emailConfirmed: true})
|
||||
await getAgent().resumeSession(getAgent().session!)
|
||||
Toast.show(_(msg`Email verified`))
|
||||
closeModal()
|
||||
onSuccess?.()
|
||||
|
|
|
@ -5,7 +5,7 @@ import {useLingui} from '@lingui/react'
|
|||
|
||||
import {cleanError} from '#/lib/strings/errors'
|
||||
import {isNative} from '#/platform/detection'
|
||||
import {useAgent, useSession, useSessionApi} from '#/state/session'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
import {ErrorMessage} from '#/view/com/util/error/ErrorMessage'
|
||||
import * as Toast from '#/view/com/util/Toast'
|
||||
import {atoms as a, useBreakpoints, useTheme} from '#/alf'
|
||||
|
@ -30,7 +30,6 @@ export function DisableEmail2FADialog({
|
|||
const t = useTheme()
|
||||
const {gtMobile} = useBreakpoints()
|
||||
const {currentAccount} = useSession()
|
||||
const {updateCurrentAccount} = useSessionApi()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
const [stage, setStage] = useState<Stages>(Stages.Email)
|
||||
|
@ -61,7 +60,7 @@ export function DisableEmail2FADialog({
|
|||
token: confirmationCode.trim(),
|
||||
emailAuthFactor: false,
|
||||
})
|
||||
updateCurrentAccount({emailAuthFactor: false})
|
||||
await getAgent().resumeSession(getAgent().session!)
|
||||
Toast.show(_(msg`Email 2FA disabled`))
|
||||
}
|
||||
control.close()
|
||||
|
|
|
@ -3,7 +3,7 @@ import {msg} from '@lingui/macro'
|
|||
import {useLingui} from '@lingui/react'
|
||||
|
||||
import {useModalControls} from '#/state/modals'
|
||||
import {useAgent, useSession, useSessionApi} from '#/state/session'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
import {ToggleButton} from 'view/com/util/forms/ToggleButton'
|
||||
import {useDialogControl} from '#/components/Dialog'
|
||||
import {DisableEmail2FADialog} from './DisableEmail2FADialog'
|
||||
|
@ -11,7 +11,6 @@ import {DisableEmail2FADialog} from './DisableEmail2FADialog'
|
|||
export function Email2FAToggle() {
|
||||
const {_} = useLingui()
|
||||
const {currentAccount} = useSession()
|
||||
const {updateCurrentAccount} = useSessionApi()
|
||||
const {openModal} = useModalControls()
|
||||
const disableDialogCtrl = useDialogControl()
|
||||
const {getAgent} = useAgent()
|
||||
|
@ -22,11 +21,9 @@ export function Email2FAToggle() {
|
|||
email: currentAccount.email,
|
||||
emailAuthFactor: true,
|
||||
})
|
||||
updateCurrentAccount({
|
||||
emailAuthFactor: true,
|
||||
})
|
||||
await getAgent().resumeSession(getAgent().session!)
|
||||
}
|
||||
}, [currentAccount, updateCurrentAccount, getAgent])
|
||||
}, [currentAccount, getAgent])
|
||||
|
||||
const onToggle = React.useCallback(() => {
|
||||
if (!currentAccount) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue