all repos — caroster @ 72728bbbc84474c84bf645ef0f29ceeffd807574

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

frontend/pages/auth/login.tsx (view raw)

 1import {useTranslation} from 'next-i18next';
 2import Layout from '../../layouts/Centered';
 3import {
 4  Card,
 5  CardContent,
 6  CardMedia,
 7  Container,
 8  Typography,
 9} from '@mui/material';
10import Logo from '../../components/Logo';
11import {getSession} from 'next-auth/react';
12import pageUtils from '../../lib/pageUtils';
13import Cookies from 'cookies';
14import LoginForm from '../../containers/LoginForm';
15
16interface Props {
17  error?: string;
18}
19
20const Login = (props: 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          <CardContent>
29            <Typography variant="h6" align="center">
30              {t('signin.title')}
31            </Typography>
32            <LoginForm error={props.error} showGoogleAuth />
33          </CardContent>
34        </Card>
35      </Container>
36    </Layout>
37  );
38};
39
40export const getServerSideProps = async (context: any) => {
41  const session = await getSession(context);
42
43  if (session)
44    return {
45      redirect: {
46        destination: '/',
47        permanent: false,
48      },
49    };
50  else
51    return pageUtils.getServerSideProps(async ctx => {
52      const error = ctx.query?.error || null;
53      const redirectPath = ctx.query?.redirectPath;
54
55      if (redirectPath) {
56        const cookies = new Cookies(ctx.req, ctx.res);
57        cookies.set('redirectPath', redirectPath);
58      }
59
60      return {props: {error}};
61    })(context);
62};
63
64export default Login;