Add dedicated local admin domain routing
This commit is contained in:
@@ -7,7 +7,7 @@ import { isRedirectError } from "next/dist/client/components/redirect-error";
|
||||
import { ZodError } from "zod";
|
||||
|
||||
import { routing } from "@/i18n/routing";
|
||||
import { toInternalAdminPath } from "@/lib/admin-routing";
|
||||
import { getAdminAppPath, toInternalAdminPath } from "@/lib/admin-routing";
|
||||
import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth";
|
||||
import { deleteEntityMediaUsages, replaceEntityMediaUsages } from "@/lib/media";
|
||||
import { resolveMediaSelection } from "@/lib/media-service";
|
||||
@@ -26,7 +26,7 @@ import {
|
||||
async function ensureAdmin() {
|
||||
if (!(await isAdminAuthenticated())) {
|
||||
await clearAdminSessionCookie();
|
||||
redirect("/");
|
||||
redirect(getAdminAppPath("/"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ async function removeManagedPaths(paths: string[]) {
|
||||
export async function upsertCategoryAction(formData: FormData) {
|
||||
await ensureAdmin();
|
||||
|
||||
const redirectPath = getRedirectPath(formData, "/portfolio/categories");
|
||||
const redirectPath = getRedirectPath(formData, getAdminAppPath("/portfolio/categories"));
|
||||
|
||||
try {
|
||||
const parsed = categoryInputSchema.parse({
|
||||
@@ -157,7 +157,7 @@ export async function upsertCategoryAction(formData: FormData) {
|
||||
export async function deleteCategoryAction(formData: FormData) {
|
||||
await ensureAdmin();
|
||||
|
||||
const redirectPath = getRedirectPath(formData, "/portfolio/categories");
|
||||
const redirectPath = getRedirectPath(formData, getAdminAppPath("/portfolio/categories"));
|
||||
const id = String(formData.get("id") ?? "");
|
||||
|
||||
try {
|
||||
@@ -192,8 +192,8 @@ export async function saveProjectAction(formData: FormData) {
|
||||
await ensureAdmin();
|
||||
|
||||
const fallbackRedirect = String(formData.get("id") ?? "").trim()
|
||||
? `/portfolio/projects/${String(formData.get("id") ?? "").trim()}`
|
||||
: "/portfolio/projects/new";
|
||||
? getAdminAppPath(`/portfolio/projects/${String(formData.get("id") ?? "").trim()}`)
|
||||
: getAdminAppPath("/portfolio/projects/new");
|
||||
const redirectPath = getRedirectPath(formData, fallbackRedirect);
|
||||
const uploadedPaths: string[] = [];
|
||||
const createdMediaAssetIds: string[] = [];
|
||||
@@ -526,7 +526,7 @@ export async function saveProjectAction(formData: FormData) {
|
||||
}
|
||||
|
||||
redirect(
|
||||
withMessage(`/portfolio/projects/${projectResult.project.id}`, "success", "Projekt gespeichert."),
|
||||
withMessage(getAdminAppPath(`/portfolio/projects/${projectResult.project.id}`), "success", "Projekt gespeichert."),
|
||||
);
|
||||
} catch (error) {
|
||||
if (isRedirectError(error)) {
|
||||
@@ -579,7 +579,7 @@ export async function deleteProjectAction(formData: FormData) {
|
||||
});
|
||||
|
||||
if (!project) {
|
||||
redirect(withMessage("/portfolio", "error", "Project not found."));
|
||||
redirect(withMessage(getAdminAppPath("/portfolio"), "error", "Project not found."));
|
||||
}
|
||||
|
||||
await prisma.portfolioProject.delete({
|
||||
@@ -596,12 +596,12 @@ export async function deleteProjectAction(formData: FormData) {
|
||||
revalidatePath(getLocalizedPath(locale, `/portfolio/${project.slug}`));
|
||||
}
|
||||
|
||||
redirect(withMessage("/portfolio", "success", "Project deleted."));
|
||||
redirect(withMessage(getAdminAppPath("/portfolio"), "success", "Project deleted."));
|
||||
} catch (error) {
|
||||
if (isRedirectError(error)) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
redirect(withMessage("/portfolio", "error", "Unable to delete project."));
|
||||
redirect(withMessage(getAdminAppPath("/portfolio"), "error", "Unable to delete project."));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user