diff options
Diffstat (limited to 'src/state/session/index.tsx')
-rw-r--r-- | src/state/session/index.tsx | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/state/session/index.tsx b/src/state/session/index.tsx index 45384c4f5..8223a7b3a 100644 --- a/src/state/session/index.tsx +++ b/src/state/session/index.tsx @@ -40,6 +40,7 @@ const ApiContext = React.createContext<SessionApiContext>({ logoutEveryAccount: async () => {}, resumeSession: async () => {}, removeAccount: () => {}, + partialRefreshSession: async () => {}, }) export function Provider({children}: React.PropsWithChildren<{}>) { @@ -119,7 +120,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) { ) const logoutCurrentAccount = React.useCallback< - SessionApiContext['logoutEveryAccount'] + SessionApiContext['logoutCurrentAccount'] >( logContext => { addSessionDebugLog({type: 'method:start', method: 'logout'}) @@ -182,6 +183,23 @@ export function Provider({children}: React.PropsWithChildren<{}>) { [onAgentSessionChange, cancelPendingTask], ) + const partialRefreshSession = React.useCallback< + SessionApiContext['partialRefreshSession'] + >(async () => { + const agent = state.currentAgentState.agent as BskyAppAgent + const signal = cancelPendingTask() + const {data} = await agent.com.atproto.server.getSession() + if (signal.aborted) return + dispatch({ + type: 'partial-refresh-session', + accountDid: agent.session!.did, + patch: { + emailConfirmed: data.emailConfirmed, + emailAuthFactor: data.emailAuthFactor, + }, + }) + }, [state, cancelPendingTask]) + const removeAccount = React.useCallback<SessionApiContext['removeAccount']>( account => { addSessionDebugLog({ @@ -262,6 +280,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) { logoutEveryAccount, resumeSession, removeAccount, + partialRefreshSession, }), [ createAccount, @@ -270,6 +289,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) { logoutEveryAccount, resumeSession, removeAccount, + partialRefreshSession, ], ) |