Skip to content

Commit 1029e67

Browse files
committed
Adds graphql logout manually
1 parent a647e8d commit 1029e67

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/components/base/hooks/useHeader.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,26 @@ import { showAuthModal } from '../../../modules/core';
44
import { RootState } from '../../../modules';
55
import { logout } from '../../../lib/api/auth';
66
import storage from '../../../lib/storage';
7+
import { useMutation } from '@apollo/react-hooks';
8+
import { LOGOUT } from '../../../lib/graphql/user';
79

810
export default function useHeader() {
911
const dispatch = useDispatch();
1012
const user = useSelector((state: RootState) => state.core.user);
1113
const customHeader = useSelector((state: RootState) => state.header);
14+
const [graphqlLogout] = useMutation(LOGOUT);
1215

1316
const onLoginClick = useCallback(() => {
1417
dispatch(showAuthModal('LOGIN'));
1518
}, [dispatch]);
1619

1720
const onLogout = useCallback(async () => {
1821
try {
19-
await logout();
22+
await Promise.all([logout(), graphqlLogout()]);
2023
} catch {}
2124
storage.removeItem('CURRENT_USER');
2225
window.location.href = '/';
23-
}, []);
26+
}, [graphqlLogout]);
2427

2528
return { user, onLoginClick, onLogout, customHeader };
2629
}

src/lib/graphql/user.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,9 @@ export const UPDATE_ABOUT = gql`
157157
}
158158
}
159159
`;
160+
161+
export const LOGOUT = gql`
162+
mutation Logout {
163+
logout
164+
}
165+
`;

0 commit comments

Comments
 (0)