You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
652 B
TypeScript

import { useContext } from 'react'
import AuthService from '@/services/AuthService'
import { AuthContext } from "@/components/Auth/AuthProvider";
export const useLogout = () => {
const { setIsAuth } = useContext(AuthContext);
const Logout = async () => {
try {
await AuthService.logout().then(
() => {
localStorage.removeItem('token');
localStorage.removeItem('user');
setIsAuth(false);
}
);
} catch (e) {
setIsAuth(false);
console.log(e);
}
}
return Logout;
}