Refactor getConfig calls

This commit is contained in:
2024-09-02 12:16:06 +02:00
parent e01a4dbd9a
commit b84efd1c61
6 changed files with 9 additions and 11 deletions

View File

@@ -11,8 +11,7 @@ export default async function AppLayout({
}: {
children: React.ReactNode;
}) {
const hostname = new URL(process.env.NEXT_PUBLIC_SITE_URL!).hostname;
const config = await getConfig(hostname);
const config = await getConfig();
const { requireLogin, privacy, browse, rooms } = config.features;
return (
<Container

View File

@@ -66,8 +66,7 @@ export default async function RootLayout({
}: {
children: React.ReactNode;
}) {
const hostname = new URL(process.env.NEXT_PUBLIC_SITE_URL!).hostname;
const config = await getConfig(hostname);
const config = await getConfig();
const hasAuthCookie = !!cookies().get(SESSION_COOKIE_NAME);
return (

View File

@@ -29,7 +29,9 @@ export function edgeDomainToKey(domain: string) {
}
// get edge config server-side (prefer DomainContext when available), domain is the hostname
export async function getConfig(domain: string) {
export async function getConfig() {
const domain = new URL(process.env.NEXT_PUBLIC_SITE_URL!).hostname;
if (process.env.NEXT_PUBLIC_ENV === "development") {
return require("../../config").localConfig;
}

View File

@@ -44,7 +44,7 @@ export const getFiefAuth = async (url: URL) => {
if (FIEF_AUTHS[url.hostname]) {
return FIEF_AUTHS[url.hostname];
} else {
const config = url && (await getConfig(url.hostname));
const config = url && (await getConfig());
if (config) {
FIEF_AUTHS[url.hostname] = new FiefAuth({
client: fiefClient,