import { createAsync, query } from "@solidjs/router";
import { useSession } from "vinxi/http";
type SessionData = {
theme: "light" | "dark";
};
const getTheme = query(async () => {
"use server";
const session = await useSession<SessionData>({
password: process.env.SESSION_SECRET as string,
name: "theme",
});
if (!session.data.theme) {
await session.update({
theme: "light",
});
}
return session.data.theme;
}, "getTheme");
export function ThemeToggle() {
const theme = createAsync(() => getTheme());
return <p>theme: {theme()}</p;
}
import { createAsync, query } from "@solidjs/router";
import { useSession } from "vinxi/http";
type SessionData = {
theme: "light" | "dark";
};
const getTheme = query(async () => {
"use server";
const session = await useSession<SessionData>({
password: process.env.SESSION_SECRET as string,
name: "theme",
});
if (!session.data.theme) {
await session.update({
theme: "light",
});
}
return session.data.theme;
}, "getTheme");
export function ThemeToggle() {
const theme = createAsync(() => getTheme());
return <p>theme: {theme()}</p;
}