Move Server Actions to static paths to fix RSC temporary client reference error
Server Actions imported from dynamic route paths ([courseId]/[moduleId]/[lessonId]) caused "Cannot access toStringTag on the server" crash after saving a lesson. Moved saveLesson, saveHomework, deleteHomework to src/lib/actions/*.ts. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
"use server";
|
||||
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { headers } from "next/headers";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
async function requireAdmin() {
|
||||
const session = await auth.api.getSession({ headers: await headers() });
|
||||
if (!session || session.user.role !== "admin") throw new Error("Forbidden");
|
||||
}
|
||||
|
||||
export async function saveHomework(lessonId: string, description: string) {
|
||||
await requireAdmin();
|
||||
await prisma.homework.upsert({
|
||||
where: { lessonId },
|
||||
update: { description },
|
||||
create: { lessonId, description },
|
||||
});
|
||||
revalidatePath(`/admin/courses`);
|
||||
}
|
||||
|
||||
export async function deleteHomework(lessonId: string) {
|
||||
await requireAdmin();
|
||||
await prisma.homework.delete({ where: { lessonId } });
|
||||
revalidatePath(`/admin/courses`);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
"use server";
|
||||
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { headers } from "next/headers";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
async function requireAdmin() {
|
||||
const session = await auth.api.getSession({ headers: await headers() });
|
||||
if (!session || session.user.role !== "admin") throw new Error("Forbidden");
|
||||
}
|
||||
|
||||
export async function saveLesson(
|
||||
lessonId: string,
|
||||
courseId: string,
|
||||
moduleId: string,
|
||||
data: {
|
||||
title: string;
|
||||
kinescopeId: string;
|
||||
content: object;
|
||||
published: boolean;
|
||||
}
|
||||
) {
|
||||
await requireAdmin();
|
||||
await prisma.lesson.update({
|
||||
where: { id: lessonId },
|
||||
data: {
|
||||
title: data.title,
|
||||
kinescopeId: data.kinescopeId || null,
|
||||
content: data.content,
|
||||
published: data.published,
|
||||
},
|
||||
});
|
||||
revalidatePath(`/admin/courses/${courseId}/modules/${moduleId}`);
|
||||
revalidatePath(`/admin/courses/${courseId}/modules/${moduleId}/lessons/${lessonId}`);
|
||||
}
|
||||
Reference in New Issue
Block a user