import { accountClient } from '../axios';
import { SetSessionExpireDate } from '../user/localStorage';
import useAuth from './useAuth';
import useAxiosWithAuth from './useAxiosWithAuth';

interface IUseLogout {
  logout: () => Promise<void>;
}

export default function useLogout(): IUseLogout {
// export default function useLogout() {
  const { setAccessToken } = useAuth();
  const client = accountClient;
  useAxiosWithAuth(client);
  const logout = async () => {
    console.log('logout');
    await client.post('Sessions/DeleteCurrent');
    SetSessionExpireDate(null);
    setAccessToken(null);
  };
  
  return { logout };
}