continued the kita-planer
This commit is contained in:
@@ -34,7 +34,7 @@ export async function getSession(): Promise<Session | null> {
|
||||
|
||||
export async function requireSession(): Promise<AuthenticatedSession> {
|
||||
const session = await auth();
|
||||
if (!session?.user) {
|
||||
if (!session?.user?.id) {
|
||||
redirect("/login");
|
||||
}
|
||||
return session as AuthenticatedSession;
|
||||
@@ -81,7 +81,9 @@ export async function requireRole(
|
||||
// interne Helfer
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
async function consentCheck(userId: string): Promise<boolean> {
|
||||
async function consentCheck(userId: string | undefined): Promise<boolean> {
|
||||
if (!userId) return false;
|
||||
|
||||
// Lazy-Import, damit `auth-utils` selbst Edge-kompatibel bleibt
|
||||
// (Prisma läuft nur in Node-Runtime).
|
||||
const { prisma } = await import("@/lib/prisma");
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const contactRequestTypeLabels = {
|
||||
GENERAL: "Allgemeine Frage",
|
||||
DEMO: "Demo anfragen",
|
||||
SETUP: "Individuelles Setup",
|
||||
} as const;
|
||||
|
||||
export const contactRequestSchema = z.object({
|
||||
name: z.string().trim().min(2, "Bitte gib deinen Namen ein.").max(120),
|
||||
kitaName: z.string().trim().max(160).optional(),
|
||||
email: z.string().trim().email("Bitte gib eine gültige E-Mail-Adresse ein."),
|
||||
requestType: z.enum(["GENERAL", "DEMO", "SETUP"]),
|
||||
message: z
|
||||
.string()
|
||||
.trim()
|
||||
.min(10, "Bitte schreib uns kurz, worum es geht.")
|
||||
.max(5000),
|
||||
});
|
||||
|
||||
export type ContactRequestInput = z.infer<typeof contactRequestSchema>;
|
||||
+6
-2
@@ -1,13 +1,14 @@
|
||||
import type { ReactNode } from "react";
|
||||
import { Resend } from "resend";
|
||||
|
||||
const resend = new Resend(process.env.RESEND_API_KEY);
|
||||
let resendClient: Resend | null = null;
|
||||
|
||||
type SendAppEmailInput = {
|
||||
to: string | string[];
|
||||
subject: string;
|
||||
react: ReactNode;
|
||||
from?: string;
|
||||
replyTo?: string | string[];
|
||||
};
|
||||
|
||||
type SendAppEmailResult =
|
||||
@@ -31,6 +32,7 @@ export async function sendAppEmail({
|
||||
subject,
|
||||
react,
|
||||
from = process.env.EMAIL_FROM,
|
||||
replyTo,
|
||||
}: SendAppEmailInput): Promise<SendAppEmailResult> {
|
||||
if (!process.env.RESEND_API_KEY) {
|
||||
return {
|
||||
@@ -47,11 +49,13 @@ export async function sendAppEmail({
|
||||
}
|
||||
|
||||
try {
|
||||
const { data, error } = await resend.emails.send({
|
||||
resendClient ??= new Resend(process.env.RESEND_API_KEY);
|
||||
const { data, error } = await resendClient.emails.send({
|
||||
from: from!,
|
||||
to,
|
||||
subject,
|
||||
react,
|
||||
replyTo,
|
||||
});
|
||||
|
||||
if (error) {
|
||||
|
||||
Reference in New Issue
Block a user