Skip to content

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

Enforce submission is only viewable by author for aot (#1718)

Nick Doan5c6b375a9ba7
diff --git a/apps/aot/src/app/events/[year]/[day]/right-wrapper.tsx b/apps/aot/src/app/events/[year]/[day]/right-wrapper.tsx
index 5e2a5c35..5d0a38e3 100644
--- a/apps/aot/src/app/events/[year]/[day]/right-wrapper.tsx
+++ b/apps/aot/src/app/events/[year]/[day]/right-wrapper.tsx
@@ -22,7 +22,7 @@ export function RightWrapper({ challenge }: RightWrapperProps) {
if (!challenge) return null;
if (segments[0] === 'submissions' && typeof segments[1] === 'string') {
- return <SubmissionOverview submissionId={segments[1]} />;
+ return <SubmissionOverview submissionId={segments[1]} userId={session?.user.id ?? ''} />;
}
// Redirect to solution on successful submission and show suggestions
diff --git a/apps/aot/src/app/events/[year]/[day]/submissions/[[...catchAll]]/_components/overview.tsx b/apps/aot/src/app/events/[year]/[day]/submissions/[[...catchAll]]/_components/overview.tsx
index 6f82ae7d..84f0bbf0 100644
--- a/apps/aot/src/app/events/[year]/[day]/submissions/[[...catchAll]]/_components/overview.tsx
+++ b/apps/aot/src/app/events/[year]/[day]/submissions/[[...catchAll]]/_components/overview.tsx
@@ -9,17 +9,18 @@ import { getChallengeSubmissionById } from '../getChallengeSubmissions';
interface SubmissionOverviewProps {
submissionId: string;
+ userId: string;
}
const codifyForMarkdown = (code: string) => {
return `\`\`\`ts
${code}`;
};
-export function SubmissionOverview({ submissionId }: SubmissionOverviewProps) {
+export function SubmissionOverview({ submissionId, userId }: SubmissionOverviewProps) {
const { year, day } = useParams();
const { data: submission } = useQuery({
- queryKey: [`submission`, submissionId],
- queryFn: () => getChallengeSubmissionById(submissionId),
+ queryKey: [`submission`, submissionId, 'userId', userId],
+ queryFn: () => getChallengeSubmissionById(submissionId, userId),
});
const code = codifyForMarkdown(submission?.code.trimStart() ?? '');
@@ -32,7 +33,13 @@ export function SubmissionOverview({ submissionId }: SubmissionOverviewProps) {
`I've completed ${submission?.challenge.name} - Advent of TypeScript ${year} https://adventofts.com/events/${year}/${day}`,
)}`;
- if (!submission) return null;
+ if (!submission) {
+ return (
+ <div className="flex h-full items-center justify-center text-neutral-500 dark:text-zinc-400">
+ <p>Submission does not exist</p>
+ </div>
+ );
+ }
return (
<>
diff --git a/apps/aot/src/app/events/[year]/[day]/submissions/[[...catchAll]]/getChallengeSubmissions.ts b/apps/aot/src/app/events/[year]/[day]/submissions/[[...catchAll]]/getChallengeSubmissions.ts
index a3add10f..1280c6f0 100644
--- a/apps/aot/src/app/events/[year]/[day]/submissions/[[...catchAll]]/getChallengeSubmissions.ts
+++ b/apps/aot/src/app/events/[year]/[day]/submissions/[[...catchAll]]/getChallengeSubmissions.ts
@@ -3,10 +3,11 @@
import { cache } from 'react';
import { prisma } from '@repo/db';
-export const getChallengeSubmissionById = cache((id: string) => {
+export const getChallengeSubmissionById = cache((submissionId: string, userId: string) => {
return prisma.submission.findFirst({
where: {
- id: Number(id),
+ id: Number(submissionId),
+ userId,
},
include: {
challenge: {