mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-06 05:40:02 -06:00
18 lines
649 B
TypeScript
18 lines
649 B
TypeScript
import { getServerSession } from "next-auth";
|
|
import { TUserLocale } from "@formbricks/types/user";
|
|
import { DEFAULT_LOCALE } from "@/lib/constants";
|
|
import { getUserLocale } from "@/lib/user/service";
|
|
import { findMatchingLocale } from "@/lib/utils/locale";
|
|
import { authOptions } from "@/modules/auth/lib/authOptions";
|
|
|
|
export const getLocale = async (): Promise<TUserLocale> => {
|
|
const session = await getServerSession(authOptions);
|
|
let locale: TUserLocale | undefined;
|
|
if (session?.user?.id) {
|
|
locale = await getUserLocale(session.user.id);
|
|
} else {
|
|
locale = await findMatchingLocale();
|
|
}
|
|
return locale ?? DEFAULT_LOCALE;
|
|
};
|