1
1
import { useMemo , useRef } from 'react' ;
2
2
import { useLocation , useNavigate } from 'react-router-dom' ;
3
3
import { InMemoryCache , NormalizedCacheObject } from '@apollo/client' ;
4
- import { useRecoilState , useRecoilValue } from 'recoil' ;
4
+ import { useRecoilState , useSetRecoilState } from 'recoil' ;
5
5
6
+ import { currentUserState } from '@/auth/states/currentUserState' ;
7
+ import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState' ;
6
8
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState' ;
7
9
import { previousUrlState } from '@/auth/states/previousUrlState' ;
8
10
import { tokenPairState } from '@/auth/states/tokenPairState' ;
11
+ import { workspacesState } from '@/auth/states/workspaces' ;
9
12
import { isDebugModeState } from '@/client-config/states/isDebugModeState' ;
10
13
import { AppPath } from '@/types/AppPath' ;
11
14
import { REACT_APP_SERVER_BASE_URL } from '~/config' ;
@@ -18,12 +21,20 @@ import { ApolloFactory, Options } from '../services/apollo.factory';
18
21
export const useApolloFactory = ( options : Partial < Options < any > > = { } ) => {
19
22
// eslint-disable-next-line @nx/workspace-no-state-useref
20
23
const apolloRef = useRef < ApolloFactory < NormalizedCacheObject > | null > ( null ) ;
21
- const currentWorkspace = useRecoilValue ( currentWorkspaceState ) ;
22
24
const [ isDebugMode ] = useRecoilState ( isDebugModeState ) ;
23
25
24
26
const navigate = useNavigate ( ) ;
25
27
const isMatchingLocation = useIsMatchingLocation ( ) ;
26
28
const [ tokenPair , setTokenPair ] = useRecoilState ( tokenPairState ) ;
29
+ const [ currentWorkspace , setCurrentWorkspace ] = useRecoilState (
30
+ currentWorkspaceState ,
31
+ ) ;
32
+ const setCurrentUser = useSetRecoilState ( currentUserState ) ;
33
+ const setCurrentWorkspaceMember = useSetRecoilState (
34
+ currentWorkspaceMemberState ,
35
+ ) ;
36
+
37
+ const setWorkspaces = useSetRecoilState ( workspacesState ) ;
27
38
const [ , setPreviousUrl ] = useRecoilState ( previousUrlState ) ;
28
39
const location = useLocation ( ) ;
29
40
@@ -49,6 +60,10 @@ export const useApolloFactory = (options: Partial<Options<any>> = {}) => {
49
60
} ,
50
61
onUnauthenticatedError : ( ) => {
51
62
setTokenPair ( null ) ;
63
+ setCurrentUser ( null ) ;
64
+ setCurrentWorkspaceMember ( null ) ;
65
+ setCurrentWorkspace ( null ) ;
66
+ setWorkspaces ( null ) ;
52
67
if (
53
68
! isMatchingLocation ( AppPath . Verify ) &&
54
69
! isMatchingLocation ( AppPath . SignInUp ) &&
@@ -69,6 +84,10 @@ export const useApolloFactory = (options: Partial<Options<any>> = {}) => {
69
84
// eslint-disable-next-line react-hooks/exhaustive-deps
70
85
} , [
71
86
setTokenPair ,
87
+ setCurrentUser ,
88
+ setCurrentWorkspaceMember ,
89
+ setCurrentWorkspace ,
90
+ setWorkspaces ,
72
91
isDebugMode ,
73
92
currentWorkspace ?. currentCacheVersion ,
74
93
setPreviousUrl ,
0 commit comments