all repos — caroster @ 65bcb7d208677b65df7ba31f656ee6ee0cfb1d1d

[Octree] Group carpool to your event https://caroster.io

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