generated from mantinedev/next-pages-template
-
-
Notifications
You must be signed in to change notification settings - Fork 255
/
index.tsx
61 lines (54 loc) · 2.06 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { GetServerSidePropsContext, InferGetServerSidePropsType } from 'next';
import { Dashboard } from '~/components/Dashboard/Dashboard';
import { BoardLayout } from '~/components/layout/Templates/BoardLayout';
import { useInitConfig } from '~/config/init';
import { getServerAuthSession } from '~/server/auth';
import { getDefaultBoardAsync } from '~/server/db/queries/userSettings';
import { getFrontendConfig } from '~/tools/config/getFrontendConfig';
import { getServerSideTranslations } from '~/tools/server/getServerSideTranslations';
import { checkForSessionOrAskForLogin } from '~/tools/server/loginBuilder';
import { boardNamespaces } from '~/tools/server/translation-namespaces';
import { api } from '~/utils/api';
import { env } from 'process';
import fs from 'fs';
export default function BoardPage({
config: initialConfig,
isDockerEnabled: isDockerEnabled,
}: InferGetServerSidePropsType<typeof getServerSideProps>) {
useInitConfig(initialConfig);
return (
<BoardLayout isDockerEnabled={isDockerEnabled}>
<Dashboard />
</BoardLayout>
);
}
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
const session = await getServerAuthSession(context);
const boardName = await getDefaultBoardAsync(session?.user?.id, 'default');
const translations = await getServerSideTranslations(
boardNamespaces,
context.locale,
context.req,
context.res
);
const config = await getFrontendConfig(boardName);
const result = checkForSessionOrAskForLogin(
context,
session,
() => config.settings.access.allowGuests || session?.user != undefined
);
if (result) {
return result;
}
const isDockerEnabled: boolean = !!env.DOCKER_HOST || !!env.DOCKER_PORT || fs.existsSync('/var/run/docker');
return {
props: {
config,
primaryColor: config.settings.customization.colors.primary,
secondaryColor: config.settings.customization.colors.secondary,
primaryShade: config.settings.customization.colors.shade,
isDockerEnabled: isDockerEnabled,
...translations,
},
};
};