1
|
import type { NextPage } from 'next';
|
2
|
import { useRouter } from 'next/router';
|
3
|
import { useContext, useEffect } from 'react';
|
4
|
import { LoggedUserContext } from '../contexts/LoggedUserContext';
|
5
|
import { getToken } from '../utils/login';
|
6
|
|
7
|
const Home: NextPage = () => {
|
8
|
const { role } = useContext(LoggedUserContext);
|
9
|
const router = useRouter();
|
10
|
|
11
|
useEffect(() => {
|
12
|
async function checkToken() {
|
13
|
let token = await getToken();
|
14
|
if (token === '') {
|
15
|
router.push('/login');
|
16
|
} else {
|
17
|
if (role === 'ADMINISTRATOR') {
|
18
|
router.push('/documents/admin');
|
19
|
} else if (role === 'ANNOTATOR') {
|
20
|
router.push('/documents/annotator');
|
21
|
}
|
22
|
}
|
23
|
}
|
24
|
|
25
|
checkToken();
|
26
|
}, [role, router]);
|
27
|
|
28
|
return null;
|
29
|
};
|
30
|
|
31
|
export default Home;
|