[Session] Dispose of stale agents immediately
parent
acf1def6c1
commit
8938fc87a0
|
@ -208,6 +208,19 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
if (IS_DEV && isWeb) window.agent = state.currentAgentState.agent
|
if (IS_DEV && isWeb) window.agent = state.currentAgentState.agent
|
||||||
|
|
||||||
const agent = state.currentAgentState.agent as BskyAgent
|
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 (
|
return (
|
||||||
<AgentContext.Provider value={agent}>
|
<AgentContext.Provider value={agent}>
|
||||||
<StateContext.Provider value={stateContext}>
|
<StateContext.Provider value={stateContext}>
|
||||||
|
|
Loading…
Reference in New Issue