-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.tsx
42 lines (37 loc) · 1.19 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { getServersideUser } from "@/koala/get-serverside-user";
import { prismaClient } from "@/koala/prisma-client";
import { Container } from "@mantine/core";
import { GetServerSideProps } from "next/types";
import * as React from "react";
// Get serverside props:
export const getServerSideProps: GetServerSideProps = async (context) => {
const dbUser = await getServersideUser(context);
if (!dbUser) {
return { redirect: { destination: "/api/auth/signin", permanent: false } };
}
const cardCount = await prismaClient.card.count({
where: { userId: dbUser.id },
});
if (cardCount === 0) {
return { redirect: { destination: "/create", permanent: false } };
}
return { redirect: { destination: "/review", permanent: false } };
};
const Index: React.FC = () => {
return (
<Container size="xs">
<header
style={{
display: "flex",
alignItems: "center",
justifyContent: "center",
marginBottom: "20px",
}}
>
<span style={{ fontSize: "24px", fontWeight: "bold" }}>Welcome</span>
</header>
<p>Click "Study" on the left panel to begin a lesson.</p>
</Container>
);
};
export default Index;