Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

😲

bautistaaae5ecde453bf3
diff --git a/apps/admin/src/app/dashboard/page.tsx b/apps/admin/src/app/dashboard/page.tsx
new file mode 100644
index 00000000..3667973d
--- /dev/null
+++ b/apps/admin/src/app/dashboard/page.tsx
@@ -0,0 +1,26 @@
+import { auth } from '@repo/auth/server';
+import { RoleTypes } from '@repo/db/types';
+import { Lock } from '@repo/ui/icons';
+import { redirect } from 'next/navigation';
+
+export async function Dashboard() {
+ const session = await auth();
+ const roles = session?.user?.role ?? [];
+
+ const isMod = roles.includes(RoleTypes.MODERATOR);
+ const isAdmin = roles.includes(RoleTypes.ADMIN);
+ const isModOrAdmin = isAdmin || isMod;
+ if (isModOrAdmin) redirect('/dashboard/reports');
+ return (
+ <div>
+ <div className="flex flex-col gap-4">
+ <div className="flex min-h-[calc(100dvh-112px)] w-full flex-col items-center justify-center space-y-2">
+ <Lock className="h-8 w-8" />
+ <span className="max-w-[40ch] text-center text-black/50 dark:text-white/50">
+ You do not have permissions to access the page.
+ </span>
+ </div>
+ </div>
+ </div>
+ );
+}
\ No newline at end of file
diff --git a/apps/admin/src/app/dashboard/reports/[id]/page.tsx b/apps/admin/src/app/dashboard/reports/[id]/page.tsx
index 2acd4d93..45f860d8 100644
--- a/apps/admin/src/app/dashboard/reports/[id]/page.tsx
+++ b/apps/admin/src/app/dashboard/reports/[id]/page.tsx
@@ -1,8 +1,10 @@
+import { auth } from '@repo/auth/server';
import { Alert, AlertDescription, AlertTitle } from '@repo/ui/components/alert';
import { Markdown } from '@repo/ui/components/markdown';
import { Text } from '@repo/ui/components/typography/typography';
import { AlertCircle, ChevronLeft } from '@repo/ui/icons';
import Link from 'next/link';
+import { assertAdmin } from '~/utils/auth-guards';
import { getReport, type ReportWithInfo } from './_actions';
import { ChallengeReport } from './_components/challenge.report';
import { CommentReport } from './_components/comment.report';
@@ -38,6 +40,9 @@ const getComponentByType = (type: ReportWithInfo['type']) => {
}[type];
};
export default async function ({ params: { id } }: Props) {
+ const session = await auth();
+ assertAdmin(session);
+
const report = await getReport(Number(id));
const ReportComponent = getComponentByType(report.type);
diff --git a/apps/admin/src/app/dashboard/tracks/[trackId]/_actions/update-track.action.ts b/apps/admin/src/app/dashboard/tracks/[trackId]/_actions/update-track.action.ts
index ed2191ec..bd141f32 100644
--- a/apps/admin/src/app/dashboard/tracks/[trackId]/_actions/update-track.action.ts
+++ b/apps/admin/src/app/dashboard/tracks/[trackId]/_actions/update-track.action.ts
@@ -1,9 +1,14 @@
'use server';
+import { auth } from '@repo/auth/server';
import { prisma } from '@repo/db';
+import { assertAdmin } from '~/utils/auth-guards';
import type { FormSchema } from '../_components/update-track-form';
export async function updateTrack(data: FormSchema & { trackId: number }) {
+ const session = await auth();
+ assertAdmin(session);
+
const { trackId, trackChallenges, ...rest } = data;
await prisma.trackChallenge.deleteMany({
where: { trackId },
diff --git a/apps/admin/src/app/layout.tsx b/apps/admin/src/app/layout.tsx
index e4e382ad..177ab1b9 100644
--- a/apps/admin/src/app/layout.tsx
+++ b/apps/admin/src/app/layout.tsx
@@ -2,9 +2,14 @@ import '../styles/globals.css';
import { Toaster } from '@repo/ui/components/toaster';
import { Inter } from 'next/font/google';
-import { Providers } from './providers';
import { Navigation } from '~/components/navigation';
+import { Providers } from './providers';
+
+import type { Metadata } from 'next';
+export const metadata: Metadata = {
+ robots: 'noindex',
+};
const inter = Inter({ subsets: ['latin'] });
export default function RootLayout({ children }: { children: React.ReactNode }) {