-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuseLogout.tsx
More file actions
29 lines (26 loc) · 903 Bytes
/
useLogout.tsx
File metadata and controls
29 lines (26 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { useAuthContext } from '@/providers/AuthContext';
import { useMutation } from '@tanstack/react-query';
import useToast from '@/hooks/useToast';
import { fe } from '../instance';
import { STORAGE_KEY_HOME_CALENDAR_FILTER_INPUT } from '@/constants/localStorageKeys';
export default function useLogout() {
const { logout: clientLogout } = useAuthContext();
const toastOn = useToast();
const logoutAPI = async () => {
const response = await fe
.get('auth/logout')
.then(res => res.json<string>());
return response;
};
return useMutation<string, Error>(logoutAPI, {
onSuccess: response => {
clientLogout();
location.href = '/login';
localStorage.removeItem(STORAGE_KEY_HOME_CALENDAR_FILTER_INPUT);
toastOn('로그아웃이 완료되었습니다.');
},
onError: error => {
console.error('Logout error:', error);
}
});
}