frontend/pages/auth/login.tsx (view raw)
1import CardMedia from '@mui/material/CardMedia';
2import Card from '@mui/material/Card';
3import Typography from '@mui/material/Typography';
4import {getSession} from 'next-auth/react';
5import {useTranslation} from 'next-i18next';
6import Layout from '../../layouts/Centered';
7import Logo from '../../components/Logo';
8import SignInForm from '../../containers/SignInForm';
9import LanguagesIcon from '../../containers/Languages/Icon';
10import pageUtils from '../../lib/pageUtils';
11import Container from '@mui/material/Container';
12import Cookies from 'cookies';
13
14interface PageProps {
15 error?: string;
16 emailConfirmation?: boolean;
17}
18
19const Login = (props: PageProps) => {
20 const {emailConfirmation} = props;
21 const {t} = useTranslation();
22
23 return (
24 <Layout menuTitle={t('signin.title')} displayMenu={false}>
25 <Container maxWidth="xs">
26 <Card sx={{pt: 2, width: '100%'}}>
27 <CardMedia component={Logo} />
28 {emailConfirmation && (
29 <Typography
30 sx={{p: 2}}
31 variant="body2"
32 align="center"
33 >{t`signin.emailConfirmation`}</Typography>
34 )}
35 <SignInForm error={props?.error} />
36 </Card>
37 </Container>
38 <LanguagesIcon />
39 </Layout>
40 );
41};
42
43export const getServerSideProps = async (context: any) => {
44 const session = await getSession(context);
45
46 if (session)
47 return {
48 redirect: {
49 destination: '/',
50 permanent: false,
51 },
52 };
53 else
54 return pageUtils.getServerSideProps(async ctx => {
55 const error = ctx.query?.error || null;
56 const emailConfirmation = ctx.query?.confirmed === 'true';
57 const redirectPath = ctx.query?.redirectPath;
58
59 if (redirectPath) {
60 const cookies = new Cookies(ctx.req, ctx.res);
61 cookies.set('redirectPath', redirectPath);
62 }
63
64 return {props: {error, emailConfirmation}};
65 })(context);
66};
67
68export default Login;