19 lines
551 B
TypeScript
19 lines
551 B
TypeScript
"use server";
|
|
|
|
import {cookies} from "next/headers";
|
|
|
|
// ✅ Get theme from cookies OR detect system preference
|
|
export async function getInitialTheme(): Promise<"dark" | "light"> {
|
|
const themeCookie = (await cookies()).get("theme")?.value;
|
|
|
|
if (themeCookie === "dark" || themeCookie === "light") {
|
|
return themeCookie;
|
|
}
|
|
|
|
// Detect system preference
|
|
const prefersDarkMode =
|
|
typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
|
|
return prefersDarkMode ? "dark" : "light";
|
|
}
|