Revize 8c45ccb0
Přidáno uživatelem hrubyjar před asi 2 roky(ů)
webapp/pages/index.tsx | ||
---|---|---|
1 | 1 |
import type { NextPage } from 'next'; |
2 |
import Head from 'next/head'; |
|
3 |
import Image from 'next/image'; |
|
4 |
import styles from '../styles/Home.module.css'; |
|
2 |
import { useRouter } from 'next/router'; |
|
3 |
import { useContext, useEffect } from 'react'; |
|
4 |
import { LoggedUserContext } from '../contexts/LoggedUserContext'; |
|
5 |
import { getToken } from '../utils/login'; |
|
5 | 6 |
|
6 | 7 |
const Home: NextPage = () => { |
7 |
return ( |
|
8 |
<div className={styles.container}> |
|
9 |
<Head> |
|
10 |
<title>Create Next App</title> |
|
11 |
<meta name="description" content="Generated by create next app" /> |
|
12 |
<link rel="icon" href="/favicon.ico" /> |
|
13 |
</Head> |
|
14 |
|
|
15 |
<main className={styles.main}> |
|
16 |
<h1 className={styles.title}> |
|
17 |
Welcome to <a href="https://nextjs.org">Next.js!</a> |
|
18 |
</h1> |
|
19 |
|
|
20 |
<div>test {'ahoj'}</div> |
|
21 |
<p className={styles.description}> |
|
22 |
Get started by editing{' '} |
|
23 |
<code className={styles.code}>pages/index.tsx</code> |
|
24 |
</p> |
|
25 |
|
|
26 |
<div className={styles.grid}> |
|
27 |
<a href="https://nextjs.org/docs" className={styles.card}> |
|
28 |
<h2>Documentation →</h2> |
|
29 |
<p>Find in-depth information about Next.js features and API.</p> |
|
30 |
</a> |
|
31 |
|
|
32 |
<a href="https://nextjs.org/learn" className={styles.card}> |
|
33 |
<h2>Learn →</h2> |
|
34 |
<p>Learn about Next.js in an interactive course with quizzes!</p> |
|
35 |
</a> |
|
36 |
|
|
37 |
<a |
|
38 |
href="https://github.com/vercel/next.js/tree/canary/examples" |
|
39 |
className={styles.card} |
|
40 |
> |
|
41 |
<h2>Examples →</h2> |
|
42 |
<p>Discover and deploy boilerplate example Next.js projects.</p> |
|
43 |
</a> |
|
44 |
|
|
45 |
<a |
|
46 |
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app" |
|
47 |
className={styles.card} |
|
48 |
> |
|
49 |
<h2>Deploy →</h2> |
|
50 |
<p> |
|
51 |
Instantly deploy your Next.js site to a public URL with |
|
52 |
Vercel. |
|
53 |
</p> |
|
54 |
</a> |
|
55 |
</div> |
|
56 |
</main> |
|
57 |
|
|
58 |
<footer className={styles.footer}> |
|
59 |
<a |
|
60 |
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app" |
|
61 |
target="_blank" |
|
62 |
rel="noopener noreferrer" |
|
63 |
> |
|
64 |
Powered by{' '} |
|
65 |
<span className={styles.logo}> |
|
66 |
<Image |
|
67 |
src="/vercel.svg" |
|
68 |
alt="Vercel Logo" |
|
69 |
width={72} |
|
70 |
height={16} |
|
71 |
/> |
|
72 |
</span> |
|
73 |
</a> |
|
74 |
</footer> |
|
75 |
</div> |
|
76 |
); |
|
8 |
const { role } = useContext(LoggedUserContext); |
|
9 |
const router = useRouter(); |
|
10 |
|
|
11 |
useEffect(() => { |
|
12 |
async function checkToken() { |
|
13 |
let token = await getToken(); |
|
14 |
if ((await getToken()) === '') { |
|
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; |
|
77 | 29 |
}; |
78 | 30 |
|
79 | 31 |
export default Home; |
Také k dispozici: Unified diff
Token management implemented, redirections