umami/pages/logout.js

27 lines
525 B
JavaScript
Raw Normal View History

2020-08-05 07:45:05 +02:00
import { useEffect } from 'react';
2020-10-01 07:34:16 +02:00
import { useRouter } from 'next/router';
import { removeItem, useApi } from 'next-basics';
import { AUTH_TOKEN } from 'lib/constants';
import { setUser } from 'store/app';
2020-07-26 01:31:07 +02:00
export default function LogoutPage() {
2020-10-01 07:34:16 +02:00
const router = useRouter();
const { post } = useApi();
2020-10-01 07:34:16 +02:00
2020-08-05 07:45:05 +02:00
useEffect(() => {
async function logout() {
await post('/logout');
}
removeItem(AUTH_TOKEN);
logout();
router.push('/login');
return () => setUser(null);
2020-08-05 07:45:05 +02:00
}, []);
2020-07-26 01:31:07 +02:00
2020-08-05 07:45:05 +02:00
return null;
2020-07-26 01:31:07 +02:00
}