mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-30 15:58:11 +01:00
37 lines
750 B
JavaScript
37 lines
750 B
JavaScript
import { useEffect } from 'react';
|
|
import { useRouter } from 'next/router';
|
|
import useApi from 'hooks/useApi';
|
|
import { setUser } from 'store/app';
|
|
import { removeClientAuthToken } from 'lib/client';
|
|
|
|
export default function LogoutPage({ disabled }) {
|
|
const router = useRouter();
|
|
const { post } = useApi();
|
|
|
|
useEffect(() => {
|
|
async function logout() {
|
|
await post('/auth/logout');
|
|
}
|
|
|
|
if (!disabled) {
|
|
removeClientAuthToken();
|
|
|
|
logout();
|
|
|
|
router.push('/login');
|
|
|
|
return () => setUser(null);
|
|
}
|
|
}, [disabled, router, post]);
|
|
|
|
return null;
|
|
}
|
|
|
|
export async function getServerSideProps() {
|
|
return {
|
|
props: {
|
|
disabled: !!(process.env.DISABLE_LOGIN || process.env.CLOUD_MODE),
|
|
},
|
|
};
|
|
}
|