about summary refs log tree commit diff
path: root/src/state
diff options
context:
space:
mode:
Diffstat (limited to 'src/state')
-rw-r--r--src/state/session/index.tsx13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/state/session/index.tsx b/src/state/session/index.tsx
index b5a985e67..af8417f8d 100644
--- a/src/state/session/index.tsx
+++ b/src/state/session/index.tsx
@@ -208,6 +208,19 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
   if (IS_DEV && isWeb) window.agent = state.currentAgentState.agent
 
   const agent = state.currentAgentState.agent as BskyAgent
+  const currentAgentRef = React.useRef(agent)
+  React.useEffect(() => {
+    if (currentAgentRef.current !== agent) {
+      // Read the previous value and immediately advance the pointer.
+      const prevAgent = currentAgentRef.current
+      currentAgentRef.current = agent
+      // We never reuse agents so let's fully neutralize the previous one.
+      // This ensures it won't try to consume any refresh tokens.
+      prevAgent.session = undefined
+      prevAgent.setPersistSessionHandler(undefined)
+    }
+  }, [agent])
+
   return (
     <AgentContext.Provider value={agent}>
       <StateContext.Provider value={stateContext}>