1
1
mirror of https://github.com/theoludwig/theoludwig.git synced 2024-09-17 05:25:54 +02:00
.profile/theme/theme.server.ts

22 lines
509 B
TypeScript

"use server"
import { cookies } from "next/headers"
import type { Theme } from "@/utils/constants"
import { COOKIE_MAX_AGE, DEFAULT_THEME, THEMES } from "@/utils/constants"
export const setTheme = (theme: Theme): void => {
cookies().set("theme", theme, {
path: "/",
maxAge: COOKIE_MAX_AGE,
})
}
export const getTheme = (): Theme => {
const theme = cookies().get("theme")?.value ?? DEFAULT_THEME
if (THEMES.includes(theme as Theme)) {
return theme as Theme
}
return DEFAULT_THEME
}