File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -4,23 +4,26 @@ import { showAuthModal } from '../../../modules/core';
4
4
import { RootState } from '../../../modules' ;
5
5
import { logout } from '../../../lib/api/auth' ;
6
6
import storage from '../../../lib/storage' ;
7
+ import { useMutation } from '@apollo/react-hooks' ;
8
+ import { LOGOUT } from '../../../lib/graphql/user' ;
7
9
8
10
export default function useHeader ( ) {
9
11
const dispatch = useDispatch ( ) ;
10
12
const user = useSelector ( ( state : RootState ) => state . core . user ) ;
11
13
const customHeader = useSelector ( ( state : RootState ) => state . header ) ;
14
+ const [ graphqlLogout ] = useMutation ( LOGOUT ) ;
12
15
13
16
const onLoginClick = useCallback ( ( ) => {
14
17
dispatch ( showAuthModal ( 'LOGIN' ) ) ;
15
18
} , [ dispatch ] ) ;
16
19
17
20
const onLogout = useCallback ( async ( ) => {
18
21
try {
19
- await logout ( ) ;
22
+ await Promise . all ( [ logout ( ) , graphqlLogout ( ) ] ) ;
20
23
} catch { }
21
24
storage . removeItem ( 'CURRENT_USER' ) ;
22
25
window . location . href = '/' ;
23
- } , [ ] ) ;
26
+ } , [ graphqlLogout ] ) ;
24
27
25
28
return { user, onLoginClick, onLogout, customHeader } ;
26
29
}
Original file line number Diff line number Diff line change @@ -157,3 +157,9 @@ export const UPDATE_ABOUT = gql`
157
157
}
158
158
}
159
159
` ;
160
+
161
+ export const LOGOUT = gql `
162
+ mutation Logout {
163
+ logout
164
+ }
165
+ ` ;
You can’t perform that action at this time.
0 commit comments