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."));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { redirect } from "next/navigation";
|
||||
import { PortfolioCategoriesManager } from "@/components/admin/portfolio-categories-manager";
|
||||
import { AdminDashboardShell } from "@/components/admin/admin-dashboard-shell";
|
||||
import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth";
|
||||
import { getAdminAppPath } from "@/lib/admin-routing";
|
||||
import { getAdminPortfolioCategories } from "@/lib/portfolio";
|
||||
|
||||
import { deleteCategoryAction, upsertCategoryAction } from "../actions";
|
||||
@@ -24,14 +25,14 @@ const copy = {
|
||||
|
||||
export default async function AdminPortfolioCategoriesPage() {
|
||||
if (!(await isAdminAuthenticated())) {
|
||||
redirect("/");
|
||||
redirect(getAdminAppPath("/"));
|
||||
}
|
||||
|
||||
async function logoutAction() {
|
||||
"use server";
|
||||
|
||||
await clearAdminSessionCookie();
|
||||
redirect("/");
|
||||
redirect(getAdminAppPath("/"));
|
||||
}
|
||||
|
||||
const categories = await getAdminPortfolioCategories();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { redirect } from "next/navigation";
|
||||
import { getAdminAppPath } from "@/lib/admin-routing";
|
||||
|
||||
export default function AdminPortfolioMediaRedirectPage() {
|
||||
redirect("/media");
|
||||
redirect(getAdminAppPath("/media"));
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { redirect } from "next/navigation";
|
||||
import { AdminDashboardShell } from "@/components/admin/admin-dashboard-shell";
|
||||
import { PortfolioProjectsOverview } from "@/components/admin/portfolio-projects-overview";
|
||||
import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth";
|
||||
import { getAdminAppPath } from "@/lib/admin-routing";
|
||||
import { getAdminPortfolioCategories, getAdminPortfolioProjects } from "@/lib/portfolio";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
@@ -33,14 +34,14 @@ export default async function AdminPortfolioPage({ searchParams }: AdminPortfoli
|
||||
const resolvedSearchParams = await searchParams;
|
||||
|
||||
if (!(await isAdminAuthenticated())) {
|
||||
redirect("/");
|
||||
redirect(getAdminAppPath("/"));
|
||||
}
|
||||
|
||||
async function logoutAction() {
|
||||
"use server";
|
||||
|
||||
await clearAdminSessionCookie();
|
||||
redirect("/");
|
||||
redirect(getAdminAppPath("/"));
|
||||
}
|
||||
|
||||
const selectedCategory = resolvedSearchParams?.category && resolvedSearchParams.category !== "__all__"
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth";
|
||||
import { getAdminAppPath } from "@/lib/admin-routing";
|
||||
import { getMediaOptions } from "@/lib/media";
|
||||
import {
|
||||
getActivePortfolioCategories,
|
||||
@@ -53,14 +54,14 @@ export default async function AdminPortfolioProjectPage({
|
||||
params,
|
||||
}: AdminPortfolioProjectPageProps) {
|
||||
if (!(await isAdminAuthenticated())) {
|
||||
redirect("/");
|
||||
redirect(getAdminAppPath("/"));
|
||||
}
|
||||
|
||||
async function logoutAction() {
|
||||
"use server";
|
||||
|
||||
await clearAdminSessionCookie();
|
||||
redirect("/");
|
||||
redirect(getAdminAppPath("/"));
|
||||
}
|
||||
|
||||
const { id } = await params;
|
||||
@@ -72,7 +73,7 @@ export default async function AdminPortfolioProjectPage({
|
||||
]);
|
||||
|
||||
if (!project) {
|
||||
redirect("/portfolio?error=Project+not+found.");
|
||||
redirect(`${getAdminAppPath("/portfolio")}?error=Project+not+found.`);
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -92,7 +93,7 @@ export default async function AdminPortfolioProjectPage({
|
||||
mediaOptions={mediaOptions}
|
||||
project={project}
|
||||
formId="portfolio-project-form"
|
||||
redirectPath={`/portfolio/projects/${project.id}`}
|
||||
redirectPath={getAdminAppPath(`/portfolio/projects/${project.id}`)}
|
||||
/>
|
||||
</MotionFade>
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import { MotionFade } from "@/components/motion-fade";
|
||||
import { PortfolioProjectForm } from "@/components/admin/portfolio-project-form";
|
||||
import { AdminDashboardShell } from "@/components/admin/admin-dashboard-shell";
|
||||
import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth";
|
||||
import { getAdminAppPath } from "@/lib/admin-routing";
|
||||
import { getMediaOptions } from "@/lib/media";
|
||||
import { getActivePortfolioCategories } from "@/lib/portfolio";
|
||||
|
||||
@@ -26,14 +27,14 @@ const copy = {
|
||||
|
||||
export default async function AdminNewPortfolioProjectPage() {
|
||||
if (!(await isAdminAuthenticated())) {
|
||||
redirect("/");
|
||||
redirect(getAdminAppPath("/"));
|
||||
}
|
||||
|
||||
async function logoutAction() {
|
||||
"use server";
|
||||
|
||||
await clearAdminSessionCookie();
|
||||
redirect("/");
|
||||
redirect(getAdminAppPath("/"));
|
||||
}
|
||||
|
||||
const [categories, mediaOptions] = await Promise.all([
|
||||
@@ -57,7 +58,7 @@ export default async function AdminNewPortfolioProjectPage() {
|
||||
categories={categories}
|
||||
mediaOptions={mediaOptions}
|
||||
formId="portfolio-project-form"
|
||||
redirectPath="/portfolio/projects/new"
|
||||
redirectPath={getAdminAppPath("/portfolio/projects/new")}
|
||||
/>
|
||||
</MotionFade>
|
||||
</div>
|
||||
|
||||
@@ -3,6 +3,7 @@ import { redirect } from "next/navigation";
|
||||
import { PortfolioProjectsOverview } from "@/components/admin/portfolio-projects-overview";
|
||||
import { AdminDashboardShell } from "@/components/admin/admin-dashboard-shell";
|
||||
import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth";
|
||||
import { getAdminAppPath } from "@/lib/admin-routing";
|
||||
import { getAdminPortfolioCategories, getAdminPortfolioProjects } from "@/lib/portfolio";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
@@ -33,14 +34,14 @@ export default async function AdminPortfolioProjectsPage({
|
||||
const resolvedSearchParams = await searchParams;
|
||||
|
||||
if (!(await isAdminAuthenticated())) {
|
||||
redirect("/");
|
||||
redirect(getAdminAppPath("/"));
|
||||
}
|
||||
|
||||
async function logoutAction() {
|
||||
"use server";
|
||||
|
||||
await clearAdminSessionCookie();
|
||||
redirect("/");
|
||||
redirect(getAdminAppPath("/"));
|
||||
}
|
||||
|
||||
const selectedCategory = resolvedSearchParams?.category && resolvedSearchParams.category !== "__all__"
|
||||
|
||||
Reference in New Issue
Block a user