Skip to content

Commit 7724612

Browse files
Done
1 parent 85315d5 commit 7724612

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/app/api/save-timetable/route.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@ import { NextRequest, NextResponse } from 'next/server';
22
import dbConnect from '@/lib/db';
33
import Timetable from '@/models/timetable';
44
import { generateShareId } from '@/lib/shareIDgenerate';
5+
import { getServerSession } from 'next-auth';
6+
import { authOptions } from '../auth/[...nextauth]/authOptions';
57

68
export async function POST(req: NextRequest) {
79
await dbConnect();
810
const body = await req.json();
911

1012
const { title, slots, owner, isPublic } = body;
13+
const session = await getServerSession(authOptions);
14+
if (session?.user?.email !== owner) {
15+
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
16+
}
1117

1218
if (!title || !slots || !owner) {
1319
return NextResponse.json({ error: 'Missing fields' }, { status: 400 });

0 commit comments

Comments
 (0)