Files
simple-react-app-kit/apps/web/src/server/app-locale.functions.ts
T

21 lines
540 B
TypeScript
Raw Normal View History

import { createServerFn } from "@tanstack/react-start"
import { isAppLocale } from "@/i18n/app-locales"
import { readAppLocale, writeAppLocale } from "./app-locale.server"
export const getAppLocale = createServerFn({ method: "GET" }).handler(() => {
return readAppLocale()
})
export const setAppLocale = createServerFn({ method: "POST" })
.validator((value: unknown) => {
if (!isAppLocale(value)) {
throw new Error("Invalid app locale")
}
return value
})
.handler(({ data }) => {
writeAppLocale(data)
})