Update API package to fix stale session issues (#9998)
This commit is contained in:
+1
-1
@@ -80,7 +80,7 @@
|
||||
"icons:optimize": "svgo -f ./assets/icons"
|
||||
},
|
||||
"dependencies": {
|
||||
"@atproto/api": "^0.19.1",
|
||||
"@atproto/api": "^0.19.3",
|
||||
"@bitdrift/react-native": "^0.6.8",
|
||||
"@braintree/sanitize-url": "^6.0.2",
|
||||
"@bsky.app/alf": "^0.1.7",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {useMutation} from '@tanstack/react-query'
|
||||
|
||||
import {useAgent, useSession, useSessionApi} from '#/state/session'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
|
||||
export function useConfirmEmail({
|
||||
onSuccess,
|
||||
@@ -8,7 +8,6 @@ export function useConfirmEmail({
|
||||
}: {onSuccess?: () => void; onError?: () => void} = {}) {
|
||||
const agent = useAgent()
|
||||
const {currentAccount} = useSession()
|
||||
const {partialRefreshSession} = useSessionApi()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({token}: {token: string}) => {
|
||||
@@ -20,7 +19,8 @@ export function useConfirmEmail({
|
||||
email: currentAccount.email.trim(),
|
||||
token: token.trim(),
|
||||
})
|
||||
await partialRefreshSession()
|
||||
// will update session state at root of app
|
||||
await agent.resumeSession(agent.session!)
|
||||
},
|
||||
onSuccess,
|
||||
onError,
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import {useMutation} from '@tanstack/react-query'
|
||||
|
||||
import {useAgent, useSession, useSessionApi} from '#/state/session'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
|
||||
export function useManageEmail2FA() {
|
||||
const agent = useAgent()
|
||||
const {currentAccount} = useSession()
|
||||
const {partialRefreshSession} = useSessionApi()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
@@ -23,7 +22,8 @@ export function useManageEmail2FA() {
|
||||
emailAuthFactor: enabled,
|
||||
token,
|
||||
})
|
||||
await partialRefreshSession()
|
||||
// will update session state at root of app
|
||||
await agent.resumeSession(agent.session!)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
import {useMutation} from '@tanstack/react-query'
|
||||
|
||||
import {useAgent, useSessionApi} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
import {useRequestEmailUpdate} from '#/components/dialogs/EmailDialog/data/useRequestEmailUpdate'
|
||||
|
||||
async function updateEmailAndRefreshSession(
|
||||
agent: ReturnType<typeof useAgent>,
|
||||
partialRefreshSession: () => Promise<void>,
|
||||
email: string,
|
||||
token?: string,
|
||||
) {
|
||||
await agent.com.atproto.server.updateEmail({email: email.trim(), token})
|
||||
await partialRefreshSession()
|
||||
await agent.resumeSession(agent.session!)
|
||||
}
|
||||
|
||||
export function useUpdateEmail() {
|
||||
const agent = useAgent()
|
||||
const {partialRefreshSession} = useSessionApi()
|
||||
const {mutateAsync: requestEmailUpdate} = useRequestEmailUpdate()
|
||||
|
||||
return useMutation<
|
||||
@@ -25,12 +23,7 @@ export function useUpdateEmail() {
|
||||
>({
|
||||
mutationFn: async ({email, token}: {email: string; token?: string}) => {
|
||||
if (token) {
|
||||
await updateEmailAndRefreshSession(
|
||||
agent,
|
||||
partialRefreshSession,
|
||||
email,
|
||||
token,
|
||||
)
|
||||
await updateEmailAndRefreshSession(agent, email, token)
|
||||
return {
|
||||
status: 'success',
|
||||
}
|
||||
@@ -41,12 +34,7 @@ export function useUpdateEmail() {
|
||||
status: 'tokenRequired',
|
||||
}
|
||||
} else {
|
||||
await updateEmailAndRefreshSession(
|
||||
agent,
|
||||
partialRefreshSession,
|
||||
email,
|
||||
token,
|
||||
)
|
||||
await updateEmailAndRefreshSession(agent, email, token)
|
||||
return {
|
||||
status: 'success',
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import {
|
||||
useSession,
|
||||
useSessionApi,
|
||||
} from '#/state/session'
|
||||
import {agentToSessionAccountOrThrow} from '#/state/session/agent'
|
||||
import {useLoggedOutViewControls} from '#/state/shell/logged-out'
|
||||
import {Logo} from '#/view/icons/Logo'
|
||||
import {atoms as a, useTheme} from '#/alf'
|
||||
@@ -37,7 +36,7 @@ export function Deactivated() {
|
||||
const {onPressSwitchAccount, pendingDid} = useAccountSwitcher()
|
||||
const {setShowLoggedOut} = useLoggedOutViewControls()
|
||||
const hasOtherAccounts = accounts.length > 1
|
||||
const {logoutCurrentAccount, resumeSession} = useSessionApi()
|
||||
const {logoutCurrentAccount} = useSessionApi()
|
||||
const agent = useAgent()
|
||||
const [pending, setPending] = React.useState(false)
|
||||
const [error, setError] = React.useState<string | undefined>()
|
||||
@@ -73,8 +72,7 @@ export function Deactivated() {
|
||||
setPending(true)
|
||||
await agent.com.atproto.server.activateAccount()
|
||||
await queryClient.resetQueries()
|
||||
const account = agentToSessionAccountOrThrow(agent)
|
||||
await resumeSession({...account, active: true, status: undefined})
|
||||
await agent.resumeSession(agent.session!)
|
||||
} catch (e: any) {
|
||||
switch (e.message) {
|
||||
case 'Bad token scope':
|
||||
@@ -95,7 +93,7 @@ export function Deactivated() {
|
||||
} finally {
|
||||
setPending(false)
|
||||
}
|
||||
}, [_, agent, queryClient, resumeSession])
|
||||
}, [_, agent, setPending, setError, queryClient])
|
||||
|
||||
return (
|
||||
<View style={[a.util_screen_outer, a.flex_1]}>
|
||||
|
||||
@@ -284,7 +284,6 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
type: 'partial-refresh-session',
|
||||
accountDid: agent.session!.did,
|
||||
patch: {
|
||||
email: data.email,
|
||||
emailConfirmed: data.emailConfirmed,
|
||||
emailAuthFactor: data.emailAuthFactor,
|
||||
},
|
||||
|
||||
@@ -58,10 +58,7 @@ export type Action =
|
||||
| {
|
||||
type: 'partial-refresh-session'
|
||||
accountDid: string
|
||||
patch: Pick<
|
||||
SessionAccount,
|
||||
'email' | 'emailConfirmed' | 'emailAuthFactor'
|
||||
>
|
||||
patch: Pick<SessionAccount, 'emailConfirmed' | 'emailAuthFactor'>
|
||||
}
|
||||
|
||||
function createPublicAgentState(): AgentState {
|
||||
@@ -242,7 +239,6 @@ let reducer = (state: State, action: Action): State => {
|
||||
* Only mutating values that are safe. Be very careful with this.
|
||||
*/
|
||||
if (agent.session) {
|
||||
agent.session.email = patch.email ?? agent.session.email
|
||||
agent.session.emailConfirmed =
|
||||
patch.emailConfirmed ?? agent.session.emailConfirmed
|
||||
agent.session.emailAuthFactor =
|
||||
@@ -259,7 +255,6 @@ let reducer = (state: State, action: Action): State => {
|
||||
if (a.did === accountDid) {
|
||||
return {
|
||||
...a,
|
||||
email: patch.email ?? a.email,
|
||||
emailConfirmed: patch.emailConfirmed ?? a.emailConfirmed,
|
||||
emailAuthFactor: patch.emailAuthFactor ?? a.emailAuthFactor,
|
||||
}
|
||||
|
||||
@@ -110,10 +110,10 @@
|
||||
tlds "^1.234.0"
|
||||
zod "^3.23.8"
|
||||
|
||||
"@atproto/api@^0.19.1":
|
||||
version "0.19.1"
|
||||
resolved "https://registry.yarnpkg.com/@atproto/api/-/api-0.19.1.tgz#62c48595def4c968d94a96f83ed9ee369768de5d"
|
||||
integrity sha512-GE94kx6PBsBAUcFne+cX3c77ZVr3/pvfeeG+GtZ1QFE8U9brrXoCoN6qwtOg6PfZk8UvpyCxLyWNfiC2GfCSJg==
|
||||
"@atproto/api@^0.19.3":
|
||||
version "0.19.3"
|
||||
resolved "https://registry.yarnpkg.com/@atproto/api/-/api-0.19.3.tgz#61de8d2e31abe9eb2b4c8f4ad124ed79d4a77e89"
|
||||
integrity sha512-G8YpBpRouHdTAIagi/QQIUZOhGd1jfBQWkJy9QfxAzjjEpPvaVOSk4e1S85QzGLm/xbzVONzGkmdtiOSfP6wVg==
|
||||
dependencies:
|
||||
"@atproto/common-web" "^0.4.18"
|
||||
"@atproto/lexicon" "^0.6.2"
|
||||
|
||||
Reference in New Issue
Block a user