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:
2026-04-25 13:58:27 +05:00
parent af8644ebce
commit 9eb21e3ab4
4 changed files with 65 additions and 2 deletions
+27
View File
@@ -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`);
}
+36
View File
@@ -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}`);
}