fix: wire editorial approval, harden registration, set production auth URL

- Wire admin approval UI to editorialService.approveEditorial so editorial
  accounts can move pending_approval -> active and log in. The approve button
  was permanently disabled and the service unreachable, so editorial users
  could never sign in.
- Surface non-validation errors (e.g. SMTP failures) on the registration
  form instead of silently redirecting to the confirmation page.
- Set BETTER_AUTH_URL default to the production domain in .env.example and
  compose.yaml so verification/reset links and the login origin check
  resolve against the live origin.
- Add scripts/check-smtp.ts to verify SMTP connectivity against the
  configured transport.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Leon TonhäuserandClaude committed 2026-08-10 23:06:13 +02:00
1 parent 907beb6e42
commit 268ea7544e
8 files changed
+228 -12

No files matched your search

+5
View File
@@ -67,6 +67,11 @@ async function registerAction(
if (error instanceof RegistrationValidationError) {
return { errors: { [error.field]: error.message } };
}
return {
errors: {
form: "Die Registrierung konnte nicht abgeschlossen werden. Bitte versuchen Sie es später erneut.",
},
};
}
redirect("/registrieren/bestaetigt");
@@ -0,0 +1,82 @@
import { beforeEach, expect, test, vi } from "vitest";
beforeEach(() => {
vi.clearAllMocks();
});
const mocks = vi.hoisted(() => ({
approveEditorial: vi.fn(),
headers: vi.fn(),
requireAdmin: vi.fn(),
revalidatePath: vi.fn(),
}));
vi.mock("next/headers", () => ({ headers: mocks.headers }));
vi.mock("next/cache", () => ({ revalidatePath: mocks.revalidatePath }));
vi.mock("@/modules/auth/principal", () => ({ requireAdmin: mocks.requireAdmin }));
vi.mock("@/modules/editorials/service", () => ({
editorialService: { approveEditorial: mocks.approveEditorial },
EditorialServiceError: class EditorialServiceError extends Error {
constructor(readonly code: string) {
super(code);
}
},
}));
import { approveEditorialAction } from "./actions";
test("the approve action rejects unauthenticated callers before touching the service", async () => {
mocks.headers.mockResolvedValue(new Headers());
mocks.requireAdmin.mockRejectedValue(new Error("ADMIN_REQUIRED"));
const formData = new FormData();
formData.set("priceEuros", "10.00");
await expect(
approveEditorialAction("00000000-0000-4000-8000-000000000001", formData),
).rejects.toThrow("ADMIN_REQUIRED");
expect(mocks.approveEditorial).not.toHaveBeenCalled();
});
test("the approve action forwards the authenticated principal and cents price to the service", async () => {
mocks.headers.mockResolvedValue(new Headers());
mocks.requireAdmin.mockResolvedValue({ userId: "admin-1" });
mocks.approveEditorial.mockResolvedValue(undefined);
const formData = new FormData();
formData.set("priceEuros", "12,50");
await approveEditorialAction("00000000-0000-4000-8000-000000000001", formData);
expect(mocks.approveEditorial).toHaveBeenCalledWith({
editorialId: "00000000-0000-4000-8000-000000000001",
priceCents: 1250,
adminUserId: "admin-1",
});
expect(mocks.revalidatePath).toHaveBeenCalledWith(
"/admin/redaktionen/00000000-0000-4000-8000-000000000001",
);
});
test("the approve action rejects a non-positive price before calling the service", async () => {
mocks.headers.mockResolvedValue(new Headers());
mocks.requireAdmin.mockResolvedValue({ userId: "admin-1" });
const formData = new FormData();
formData.set("priceEuros", "0");
await expect(
approveEditorialAction("00000000-0000-4000-8000-000000000001", formData),
).rejects.toThrow("Bitte geben Sie einen gültigen Nettopreis an.");
expect(mocks.approveEditorial).not.toHaveBeenCalled();
});
test("the approve action translates a service error into a German message", async () => {
mocks.headers.mockResolvedValue(new Headers());
mocks.requireAdmin.mockResolvedValue({ userId: "admin-1" });
const { EditorialServiceError } = await import("@/modules/editorials/service");
mocks.approveEditorial.mockRejectedValue(new EditorialServiceError("ALBUM_GRANT_REQUIRED"));
const formData = new FormData();
formData.set("priceEuros", "10.00");
await expect(
approveEditorialAction("00000000-0000-4000-8000-000000000001", formData),
).rejects.toThrow("Bitte weisen Sie zuerst mindestens ein Album zu.");
});
+62
View File
@@ -0,0 +1,62 @@
"use server";
import { revalidatePath } from "next/cache";
import { headers } from "next/headers";
import { requireAdmin } from "@/modules/auth/principal";
import { editorialService, EditorialServiceError } from "@/modules/editorials/service";
export async function approveEditorialAction(editorialId: string, formData: FormData): Promise<void> {
const principal = await requireAdmin(new Headers(await headers()));
const safeEditorialId = requiredId(editorialId);
const priceCents = parsePriceCents(formData.get("priceEuros"));
try {
await editorialService.approveEditorial({
editorialId: safeEditorialId,
priceCents,
adminUserId: principal.userId,
});
} catch (error) {
throw new Error(approveErrorMessage(error));
}
revalidatePath(`/admin/redaktionen/${safeEditorialId}`);
revalidatePath(`/admin/redaktionen`);
}
function parsePriceCents(value: unknown): number {
const euros =
typeof value === "string" ? Number.parseFloat(value.replace(",", ".")) : Number.NaN;
if (!Number.isFinite(euros) || euros <= 0) {
throw new Error("Bitte geben Sie einen gültigen Nettopreis an.");
}
return Math.round(euros * 100);
}
function approveErrorMessage(error: unknown): string {
if (error instanceof EditorialServiceError) {
const messages: Record<string, string> = {
INVALID_PRICE: "Bitte geben Sie einen gültigen Nettopreis an.",
EDITORIAL_NOT_FOUND: "Redaktion nicht gefunden.",
EMAIL_NOT_VERIFIED: "Die E-Mail-Adresse der Redaktion ist noch nicht bestätigt.",
ALBUM_GRANT_REQUIRED: "Bitte weisen Sie zuerst mindestens ein Album zu.",
INVALID_ACCOUNT_TRANSITION:
"Die Redaktion kann in ihrem aktuellen Status nicht freigegeben werden.",
APPROVAL_NOTICE_DELIVERY_UNKNOWN:
"Der Freigabe-Hinweis konnte nicht eindeutig zugeordnet werden.",
};
return messages[error.code] ?? "Die Freigabe ist fehlgeschlagen.";
}
return "Die Freigabe ist fehlgeschlagen.";
}
function requiredId(value: unknown): string {
if (
typeof value !== "string" ||
!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value)
) {
throw new Error("INVALID_ID");
}
return value;
}