Add email notifications via Resend

- src/lib/email.ts: HTML templates for 4 email types (Second Brain design)
- Welcome email on user registration (Better Auth databaseHooks)
- Course access email when admin grants enrollment
- Homework submitted email to all admins/curators (first submission only)
- Feedback received email to student with feedback text and lesson link
- Update TECHNICAL.md: Resend domain, from-address, email vars, Stage 3 summary

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-07 14:46:46 +05:00
parent 9bc18247df
commit 6975a9f97e
6 changed files with 195 additions and 4 deletions
@@ -4,6 +4,7 @@ import { prisma } from "@/lib/prisma";
import { auth } from "@/lib/auth";
import { headers } from "next/headers";
import { revalidatePath } from "next/cache";
import { sendFeedbackReceivedEmail } from "@/lib/email";
export async function submitFeedback(submissionId: string, text: string) {
const session = await auth.api.getSession({ headers: await headers() });
@@ -15,6 +16,36 @@ export async function submitFeedback(submissionId: string, text: string) {
data: { submissionId, curatorId: session.user.id, text },
});
// Send email to student
const submission = await prisma.homeworkSubmission.findUnique({
where: { id: submissionId },
include: {
user: { select: { email: true, name: true } },
homework: {
include: {
lesson: {
select: {
title: true,
module: { select: { course: { select: { slug: true } } } },
},
},
},
},
},
});
if (submission) {
const { lesson } = submission.homework;
const lessonUrl = `${process.env.BETTER_AUTH_URL ?? "https://school.second-brain.ru"}/courses/${lesson.module.course.slug}/lessons/${submission.homework.lessonId}`;
await sendFeedbackReceivedEmail(
submission.user.email,
submission.user.name,
lesson.title,
text,
lessonUrl
);
}
revalidatePath("/curator/homework");
revalidatePath(`/curator/homework/${submissionId}`);
}