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';
|
2022-12-28 05:20:44 +01:00
|
|
|
import useApi from 'hooks/useApi';
|
2022-02-23 07:47:59 +01:00
|
|
|
import { setUser } from 'store/app';
|
2022-12-28 05:20:44 +01:00
|
|
|
import { removeClientAuthToken } from 'lib/client';
|
2020-07-26 01:31:07 +02:00
|
|
|
|
2023-02-28 05:03:04 +01:00
|
|
|
export default function LogoutPage({ disabled }) {
|
2020-10-01 07:34:16 +02:00
|
|
|
const router = useRouter();
|
2022-11-08 01:22:49 +01:00
|
|
|
const { post } = useApi();
|
2020-10-01 07:34:16 +02:00
|
|
|
|
2020-08-05 07:45:05 +02:00
|
|
|
useEffect(() => {
|
2022-11-08 01:22:49 +01:00
|
|
|
async function logout() {
|
2023-04-13 07:53:38 +02:00
|
|
|
await post('/auth/logout');
|
2022-11-08 01:22:49 +01:00
|
|
|
}
|
|
|
|
|
2023-02-28 05:03:04 +01:00
|
|
|
if (!disabled) {
|
|
|
|
removeClientAuthToken();
|
2022-11-08 01:22:49 +01:00
|
|
|
|
2023-02-28 05:03:04 +01:00
|
|
|
logout();
|
2022-11-08 01:22:49 +01:00
|
|
|
|
2023-02-28 05:03:04 +01:00
|
|
|
router.push('/login');
|
2022-02-23 07:47:59 +01:00
|
|
|
|
2023-02-28 05:03:04 +01:00
|
|
|
return () => setUser(null);
|
|
|
|
}
|
|
|
|
}, [disabled, router, post]);
|
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
|
|
|
}
|
2023-02-28 05:03:04 +01:00
|
|
|
|
|
|
|
export async function getServerSideProps() {
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
disabled: !!(process.env.DISABLE_LOGIN || process.env.CLOUD_MODE),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|