Bluesky app fork with some witchin' additions 💫

Update API package to fix stale session issues (#9998)

authored by

Eric Bailey and committed by
GitHub
7fd218c9 8446efb7

+19 -39
+1 -1
package.json
··· 80 80 "icons:optimize": "svgo -f ./assets/icons" 81 81 }, 82 82 "dependencies": { 83 - "@atproto/api": "^0.19.1", 83 + "@atproto/api": "^0.19.3", 84 84 "@bitdrift/react-native": "^0.6.8", 85 85 "@braintree/sanitize-url": "^6.0.2", 86 86 "@bsky.app/alf": "^0.1.7",
+3 -3
src/components/dialogs/EmailDialog/data/useConfirmEmail.ts
··· 1 1 import {useMutation} from '@tanstack/react-query' 2 2 3 - import {useAgent, useSession, useSessionApi} from '#/state/session' 3 + import {useAgent, useSession} from '#/state/session' 4 4 5 5 export function useConfirmEmail({ 6 6 onSuccess, ··· 8 8 }: {onSuccess?: () => void; onError?: () => void} = {}) { 9 9 const agent = useAgent() 10 10 const {currentAccount} = useSession() 11 - const {partialRefreshSession} = useSessionApi() 12 11 13 12 return useMutation({ 14 13 mutationFn: async ({token}: {token: string}) => { ··· 20 19 email: currentAccount.email.trim(), 21 20 token: token.trim(), 22 21 }) 23 - await partialRefreshSession() 22 + // will update session state at root of app 23 + await agent.resumeSession(agent.session!) 24 24 }, 25 25 onSuccess, 26 26 onError,
+3 -3
src/components/dialogs/EmailDialog/data/useManageEmail2FA.ts
··· 1 1 import {useMutation} from '@tanstack/react-query' 2 2 3 - import {useAgent, useSession, useSessionApi} from '#/state/session' 3 + import {useAgent, useSession} from '#/state/session' 4 4 5 5 export function useManageEmail2FA() { 6 6 const agent = useAgent() 7 7 const {currentAccount} = useSession() 8 - const {partialRefreshSession} = useSessionApi() 9 8 10 9 return useMutation({ 11 10 mutationFn: async ({ ··· 23 22 emailAuthFactor: enabled, 24 23 token, 25 24 }) 26 - await partialRefreshSession() 25 + // will update session state at root of app 26 + await agent.resumeSession(agent.session!) 27 27 }, 28 28 }) 29 29 }
+4 -16
src/components/dialogs/EmailDialog/data/useUpdateEmail.ts
··· 1 1 import {useMutation} from '@tanstack/react-query' 2 2 3 - import {useAgent, useSessionApi} from '#/state/session' 3 + import {useAgent} from '#/state/session' 4 4 import {useRequestEmailUpdate} from '#/components/dialogs/EmailDialog/data/useRequestEmailUpdate' 5 5 6 6 async function updateEmailAndRefreshSession( 7 7 agent: ReturnType<typeof useAgent>, 8 - partialRefreshSession: () => Promise<void>, 9 8 email: string, 10 9 token?: string, 11 10 ) { 12 11 await agent.com.atproto.server.updateEmail({email: email.trim(), token}) 13 - await partialRefreshSession() 12 + await agent.resumeSession(agent.session!) 14 13 } 15 14 16 15 export function useUpdateEmail() { 17 16 const agent = useAgent() 18 - const {partialRefreshSession} = useSessionApi() 19 17 const {mutateAsync: requestEmailUpdate} = useRequestEmailUpdate() 20 18 21 19 return useMutation< ··· 25 23 >({ 26 24 mutationFn: async ({email, token}: {email: string; token?: string}) => { 27 25 if (token) { 28 - await updateEmailAndRefreshSession( 29 - agent, 30 - partialRefreshSession, 31 - email, 32 - token, 33 - ) 26 + await updateEmailAndRefreshSession(agent, email, token) 34 27 return { 35 28 status: 'success', 36 29 } ··· 41 34 status: 'tokenRequired', 42 35 } 43 36 } else { 44 - await updateEmailAndRefreshSession( 45 - agent, 46 - partialRefreshSession, 47 - email, 48 - token, 49 - ) 37 + await updateEmailAndRefreshSession(agent, email, token) 50 38 return { 51 39 status: 'success', 52 40 }
+3 -5
src/screens/Deactivated.tsx
··· 14 14 useSession, 15 15 useSessionApi, 16 16 } from '#/state/session' 17 - import {agentToSessionAccountOrThrow} from '#/state/session/agent' 18 17 import {useLoggedOutViewControls} from '#/state/shell/logged-out' 19 18 import {Logo} from '#/view/icons/Logo' 20 19 import {atoms as a, useTheme} from '#/alf' ··· 37 36 const {onPressSwitchAccount, pendingDid} = useAccountSwitcher() 38 37 const {setShowLoggedOut} = useLoggedOutViewControls() 39 38 const hasOtherAccounts = accounts.length > 1 40 - const {logoutCurrentAccount, resumeSession} = useSessionApi() 39 + const {logoutCurrentAccount} = useSessionApi() 41 40 const agent = useAgent() 42 41 const [pending, setPending] = React.useState(false) 43 42 const [error, setError] = React.useState<string | undefined>() ··· 73 72 setPending(true) 74 73 await agent.com.atproto.server.activateAccount() 75 74 await queryClient.resetQueries() 76 - const account = agentToSessionAccountOrThrow(agent) 77 - await resumeSession({...account, active: true, status: undefined}) 75 + await agent.resumeSession(agent.session!) 78 76 } catch (e: any) { 79 77 switch (e.message) { 80 78 case 'Bad token scope': ··· 95 93 } finally { 96 94 setPending(false) 97 95 } 98 - }, [_, agent, queryClient, resumeSession]) 96 + }, [_, agent, setPending, setError, queryClient]) 99 97 100 98 return ( 101 99 <View style={[a.util_screen_outer, a.flex_1]}>
-1
src/state/session/index.tsx
··· 284 284 type: 'partial-refresh-session', 285 285 accountDid: agent.session!.did, 286 286 patch: { 287 - email: data.email, 288 287 emailConfirmed: data.emailConfirmed, 289 288 emailAuthFactor: data.emailAuthFactor, 290 289 },
+1 -6
src/state/session/reducer.ts
··· 58 58 | { 59 59 type: 'partial-refresh-session' 60 60 accountDid: string 61 - patch: Pick< 62 - SessionAccount, 63 - 'email' | 'emailConfirmed' | 'emailAuthFactor' 64 - > 61 + patch: Pick<SessionAccount, 'emailConfirmed' | 'emailAuthFactor'> 65 62 } 66 63 67 64 function createPublicAgentState(): AgentState { ··· 242 239 * Only mutating values that are safe. Be very careful with this. 243 240 */ 244 241 if (agent.session) { 245 - agent.session.email = patch.email ?? agent.session.email 246 242 agent.session.emailConfirmed = 247 243 patch.emailConfirmed ?? agent.session.emailConfirmed 248 244 agent.session.emailAuthFactor = ··· 259 255 if (a.did === accountDid) { 260 256 return { 261 257 ...a, 262 - email: patch.email ?? a.email, 263 258 emailConfirmed: patch.emailConfirmed ?? a.emailConfirmed, 264 259 emailAuthFactor: patch.emailAuthFactor ?? a.emailAuthFactor, 265 260 }
+4 -4
yarn.lock
··· 110 110 tlds "^1.234.0" 111 111 zod "^3.23.8" 112 112 113 - "@atproto/api@^0.19.1": 114 - version "0.19.1" 115 - resolved "https://registry.yarnpkg.com/@atproto/api/-/api-0.19.1.tgz#62c48595def4c968d94a96f83ed9ee369768de5d" 116 - integrity sha512-GE94kx6PBsBAUcFne+cX3c77ZVr3/pvfeeG+GtZ1QFE8U9brrXoCoN6qwtOg6PfZk8UvpyCxLyWNfiC2GfCSJg== 113 + "@atproto/api@^0.19.3": 114 + version "0.19.3" 115 + resolved "https://registry.yarnpkg.com/@atproto/api/-/api-0.19.3.tgz#61de8d2e31abe9eb2b4c8f4ad124ed79d4a77e89" 116 + integrity sha512-G8YpBpRouHdTAIagi/QQIUZOhGd1jfBQWkJy9QfxAzjjEpPvaVOSk4e1S85QzGLm/xbzVONzGkmdtiOSfP6wVg== 117 117 dependencies: 118 118 "@atproto/common-web" "^0.4.18" 119 119 "@atproto/lexicon" "^0.6.2"