mirror of
https://github.com/ajnart/homarr.git
synced 2026-01-17 13:02:18 +01:00
🐛 Fix issue with slug board page
This commit is contained in:
@@ -1,33 +1,33 @@
|
||||
import { TRPCError } from '@trpc/server';
|
||||
import { GetServerSideProps, InferGetServerSidePropsType } from 'next';
|
||||
import { SSRConfig } from 'next-i18next';
|
||||
import { z } from 'zod';
|
||||
import { BoardProvider } from '~/components/Board/context';
|
||||
import { Board } from '~/components/Dashboard/Dashboard';
|
||||
import { BoardLayout } from '~/components/layout/Templates/BoardLayout';
|
||||
import { useInitConfig } from '~/config/init';
|
||||
import { env } from '~/env';
|
||||
import { createTrpcServersideHelpers } from '~/server/api/helper';
|
||||
import { getServerAuthSession } from '~/server/auth';
|
||||
import { configExists } from '~/tools/config/configExists';
|
||||
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 { ConfigType } from '~/types/config';
|
||||
import { RouterOutputs } from '~/utils/api';
|
||||
|
||||
export default function BoardPage({
|
||||
config: initialConfig,
|
||||
board,
|
||||
dockerEnabled,
|
||||
}: InferGetServerSidePropsType<typeof getServerSideProps>) {
|
||||
useInitConfig(initialConfig);
|
||||
|
||||
return (
|
||||
<BoardLayout dockerEnabled={dockerEnabled}>
|
||||
<Board />
|
||||
</BoardLayout>
|
||||
<BoardProvider initialBoard={board}>
|
||||
<BoardLayout dockerEnabled={dockerEnabled}>
|
||||
<Board />
|
||||
</BoardLayout>
|
||||
</BoardProvider>
|
||||
);
|
||||
}
|
||||
|
||||
type BoardGetServerSideProps = {
|
||||
config: ConfigType;
|
||||
board: RouterOutputs['boards']['byName'];
|
||||
dockerEnabled: boolean;
|
||||
_nextI18Next?: SSRConfig['_nextI18Next'];
|
||||
};
|
||||
@@ -44,14 +44,6 @@ export const getServerSideProps: GetServerSideProps<BoardGetServerSideProps> = a
|
||||
};
|
||||
}
|
||||
|
||||
const isPresent = configExists(routeParams.data.slug);
|
||||
if (!isPresent) {
|
||||
return {
|
||||
notFound: true,
|
||||
};
|
||||
}
|
||||
|
||||
const config = await getFrontendConfig(routeParams.data.slug);
|
||||
const translations = await getServerSideTranslations(
|
||||
boardNamespaces,
|
||||
ctx.locale,
|
||||
@@ -59,12 +51,28 @@ export const getServerSideProps: GetServerSideProps<BoardGetServerSideProps> = a
|
||||
ctx.res
|
||||
);
|
||||
|
||||
const helpers = await createTrpcServersideHelpers(ctx);
|
||||
const board = await helpers.boards.byName
|
||||
.fetch({ boardName: routeParams.data.slug })
|
||||
.catch((err) => {
|
||||
if (err instanceof TRPCError && err.code === 'NOT_FOUND') {
|
||||
return null;
|
||||
}
|
||||
throw err;
|
||||
});
|
||||
|
||||
if (!board) {
|
||||
return {
|
||||
notFound: true,
|
||||
};
|
||||
}
|
||||
|
||||
const session = await getServerAuthSession({ req: ctx.req, res: ctx.res });
|
||||
|
||||
const result = checkForSessionOrAskForLogin(
|
||||
ctx,
|
||||
session,
|
||||
() => config.settings.access.allowGuests || !session?.user
|
||||
() => board.allowGuests || !!session?.user
|
||||
);
|
||||
if (result) {
|
||||
return result;
|
||||
@@ -72,10 +80,10 @@ export const getServerSideProps: GetServerSideProps<BoardGetServerSideProps> = a
|
||||
|
||||
return {
|
||||
props: {
|
||||
config,
|
||||
primaryColor: config.settings.customization.colors.primary,
|
||||
secondaryColor: config.settings.customization.colors.secondary,
|
||||
primaryShade: config.settings.customization.colors.shade,
|
||||
board,
|
||||
primaryColor: board.primaryColor,
|
||||
secondaryColor: board.secondaryColor,
|
||||
primaryShade: board.primaryShade,
|
||||
dockerEnabled: !!env.DOCKER_HOST && !!env.DOCKER_PORT,
|
||||
...translations,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user