From 05ea7e5febe29ce55d60fcc3b5b0082c04a5d91d Mon Sep 17 00:00:00 2001 From: "Sakamoto, Kazunori" Date: Sat, 12 Oct 2024 00:03:37 +0900 Subject: [PATCH] feat: add debug button for admin --- .../[lectureId]/problems/[problemId]/page.tsx | 4 ++ .../problems/[problemId]/pageOnClient.tsx | 53 +++++++++++++------ 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/app/(withAuth)/courses/[courseId]/lectures/[lectureId]/problems/[problemId]/page.tsx b/src/app/(withAuth)/courses/[courseId]/lectures/[lectureId]/problems/[problemId]/page.tsx index d51e5ab2..f687eca0 100644 --- a/src/app/(withAuth)/courses/[courseId]/lectures/[lectureId]/problems/[problemId]/page.tsx +++ b/src/app/(withAuth)/courses/[courseId]/lectures/[lectureId]/problems/[problemId]/page.tsx @@ -1,4 +1,5 @@ import type { NextPage } from 'next'; +import SuperTokensNode from 'supertokens-node'; import { logger } from '../../../../../../../../infrastructures/pino'; import { prisma } from '../../../../../../../../infrastructures/prisma'; @@ -13,6 +14,8 @@ type Props = { const ProblemPage: NextPage = async (props) => { const session = await getNonNullableSessionOnServer(); + const superTokensUser = session && (await SuperTokensNode.getUser(session.superTokensUserId)); + const isAdmin = superTokensUser?.emails[0]?.endsWith('@internet.ac.jp'); let incompleteProblemSession = await prisma.problemSession.findFirst({ where: { @@ -42,6 +45,7 @@ const ProblemPage: NextPage = async (props) => { return ( diff --git a/src/app/(withAuth)/courses/[courseId]/lectures/[lectureId]/problems/[problemId]/pageOnClient.tsx b/src/app/(withAuth)/courses/[courseId]/lectures/[lectureId]/problems/[problemId]/pageOnClient.tsx index 6b98dfc9..8b791082 100644 --- a/src/app/(withAuth)/courses/[courseId]/lectures/[lectureId]/problems/[problemId]/pageOnClient.tsx +++ b/src/app/(withAuth)/courses/[courseId]/lectures/[lectureId]/problems/[problemId]/pageOnClient.tsx @@ -28,9 +28,10 @@ import { courseIdToLectureIds, courseIdToName, problemIdToName } from '../../../ import { ProblemBody } from './ProblmBody'; type Props = { + initialProblemSession: ProblemSession; + isAdmin: boolean | undefined; params: { courseId: CourseId; lectureId: string; problemId: ProblemId }; userId: string; - initialProblemSession: ProblemSession; }; export const ProblemPageOnClient: React.FC = (props) => { @@ -106,23 +107,41 @@ export const ProblemPageOnClient: React.FC = (props) => { {problemIdToName[props.params.problemId]} - - - + + + {props.isAdmin && ( + + )} +