feat: add install mode verification

This commit is contained in:
swve 2023-07-12 12:52:25 +01:00
parent 6e9998d45c
commit ce50fa760f
7 changed files with 64 additions and 15 deletions

View file

@ -1,3 +1,4 @@
import { isInstallModeEnabled } from "@services/install/install";
import { LEARNHOUSE_DOMAIN, getDefaultOrg, isMultiOrgModeEnabled } from "./services/config/config";
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
@ -16,7 +17,7 @@ export const config = {
],
};
export default function middleware(req: NextRequest) {
export default async function middleware(req: NextRequest) {
// Get initial data
const hosting_mode = isMultiOrgModeEnabled() ? "multi" : "single";
const default_org = getDefaultOrg();
@ -30,7 +31,13 @@ export default function middleware(req: NextRequest) {
// Install Page
if (pathname.startsWith("/install")) {
return NextResponse.rewrite(new URL(pathname, req.url));
// Check if install mode is enabled
const install_mode = await isInstallModeEnabled();
if (install_mode) {
return NextResponse.rewrite(new URL(pathname, req.url));
} else {
return NextResponse.redirect(new URL("/", req.url));
}
}
// Dynamic Pages Editor