1+ import { useAuthStore } from "@features/auth/stores/authStore" ;
12import { usePanelLayoutStore } from "@features/panels/store/panelLayoutStore" ;
23import { useRightSidebarStore } from "@features/right-sidebar" ;
34import { useSettingsDialogStore } from "@features/settings/stores/settingsDialogStore" ;
@@ -9,8 +10,10 @@ import { useFocusWorkspace } from "@features/workspace/hooks/useFocusWorkspace";
910import { useWorkspaceStore } from "@features/workspace/stores/workspaceStore" ;
1011import { SHORTCUTS } from "@renderer/constants/keyboard-shortcuts" ;
1112import { clearApplicationStorage } from "@renderer/lib/clearStorage" ;
13+ import { logger } from "@renderer/lib/logger" ;
1214import { useRegisteredFoldersStore } from "@renderer/stores/registeredFoldersStore" ;
1315import { trpcReact } from "@renderer/trpc" ;
16+ import { trpcVanilla } from "@renderer/trpc/client" ;
1417import type { Task } from "@shared/types" ;
1518import { useNavigationStore } from "@stores/navigationStore" ;
1619import { useCallback , useEffect , useMemo } from "react" ;
@@ -139,6 +142,26 @@ export function GlobalEventHandlers({
139142 clearApplicationStorage ( ) ;
140143 } , [ ] ) ;
141144
145+ const handleInvalidateToken = useCallback ( ( data ?: unknown ) => {
146+ if ( ! data ) return ;
147+ const log = logger . scope ( "global-event-handlers" ) ;
148+ const state = useAuthStore . getState ( ) ;
149+ const currentToken = state . oauthAccessToken ;
150+ if ( ! currentToken ) {
151+ log . warn ( "No access token to invalidate" ) ;
152+ return ;
153+ }
154+ const invalidToken = `${ currentToken } _invalid` ;
155+ useAuthStore . setState ( { oauthAccessToken : invalidToken } ) ;
156+ trpcVanilla . agent . updateToken
157+ . mutate ( { token : invalidToken } )
158+ . catch ( ( err ) => log . warn ( "Failed to update agent token" , err ) ) ;
159+ trpcVanilla . cloudTask . updateToken
160+ . mutate ( { token : invalidToken } )
161+ . catch ( ( err ) => log . warn ( "Failed to update cloud task token" , err ) ) ;
162+ log . info ( "OAuth access token invalidated for testing" ) ;
163+ } , [ ] ) ;
164+
142165 const globalOptions = {
143166 enableOnFormTags : true ,
144167 enableOnContentEditable : true ,
@@ -244,5 +267,9 @@ export function GlobalEventHandlers({
244267 onData : handleClearStorage ,
245268 } ) ;
246269
270+ trpcReact . ui . onInvalidateToken . useSubscription ( undefined , {
271+ onData : handleInvalidateToken ,
272+ } ) ;
273+
247274 return null ;
248275}
0 commit comments