Created
February 9, 2025 18:50
-
-
Save MinSomai/a82997f11e10e73962502366d8fb7634 to your computer and use it in GitHub Desktop.
payloadCMS always light theme middleware.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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