Projekt

Obecné

Profil

Stáhnout (888 Bajtů) Statistiky
| Větev: | Tag: | Revize:
1 56cc66d8 Lukáš Vlček
import type { NextPage } from 'next';
2 8c45ccb0 hrubyjar
import { useRouter } from 'next/router';
3
import { useContext, useEffect } from 'react';
4
import { LoggedUserContext } from '../contexts/LoggedUserContext';
5
import { getToken } from '../utils/login';
6 56cc66d8 Lukáš Vlček
7
const Home: NextPage = () => {
8 8c45ccb0 hrubyjar
    const { role } = useContext(LoggedUserContext);
9
    const router = useRouter();
10
11
    useEffect(() => {
12
        async function checkToken() {
13
            let token = await getToken();
14 a37f82ce Lukáš Vlček
            if (token === '') {
15 8c45ccb0 hrubyjar
                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 56cc66d8 Lukáš Vlček
};
30
31
export default Home;