Skip to content

Instantly share code, notes, and snippets.

@MinSomai
Created February 9, 2025 18:50
Show Gist options
  • Save MinSomai/a82997f11e10e73962502366d8fb7634 to your computer and use it in GitHub Desktop.
Save MinSomai/a82997f11e10e73962502366d8fb7634 to your computer and use it in GitHub Desktop.
payloadCMS always light theme middleware.
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
export function middleware(req: NextRequest) {
const res = NextResponse.next();
const currentTheme = req.cookies.get("payload-theme");
if (!req.cookies.has("payload-theme") || currentTheme?.value === "dark") {
res.cookies.set("payload-theme", "light")
}
return res;
}
// Apply middleware to all admin routes
export const config = {
matcher: "/admin/:path*",
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment