fix HostnameCheck

This commit is contained in:
biersoeckli
2024-11-22 12:58:00 +00:00
parent c061ccae3e
commit 602834b218
4 changed files with 45 additions and 32 deletions

View File

@@ -1,11 +1,10 @@
import ProjectPage from "./projects/project-page";
import paramService, { ParamService } from "@/server/services/param.service";
import HostnameCheck from "../components/custom/hostname-check";
import HostnameCheck from "./settings/server/hostname-check";
export default async function Home() {
const configuredDomain = await paramService.getString(ParamService.QS_SERVER_HOSTNAME);
return <>
<ProjectPage />
<HostnameCheck serverParamHostname={configuredDomain} />
<HostnameCheck />
</>;
}

View File

@@ -1,10 +1,11 @@
'use server'
import { getAuthUserSession, saveFormAction } from "@/server/utils/action-wrapper.utils";
import { getAuthUserSession, saveFormAction, simpleAction } from "@/server/utils/action-wrapper.utils";
import paramService, { ParamService } from "@/server/services/param.service";
import { QsIngressSettingsModel, qsIngressSettingsZodModel } from "@/model/qs-settings.model";
import { QsLetsEncryptSettingsModel, qsLetsEncryptSettingsZodModel } from "@/model/qs-letsencrypt-settings.model";
import quickStackService from "@/server/services/qs.service";
import { ServerActionResult } from "@/model/server-action-error-return.model";
export const updateIngressSettings = async (prevState: any, inputData: QsIngressSettingsModel) =>
saveFormAction(inputData, qsIngressSettingsZodModel, async (validatedData) => {
@@ -39,3 +40,10 @@ export const updateLetsEncryptSettings = async (prevState: any, inputData: QsLet
await quickStackService.createOrUpdateCertIssuer(validatedData.letsEncryptMail);
});
export const getConfiguredHostname: () => Promise<ServerActionResult<unknown, string | undefined>> = async () =>
simpleAction(async () => {
await getAuthUserSession();
return await paramService.getString(ParamService.QS_SERVER_HOSTNAME);
});

View File

@@ -0,0 +1,34 @@
'use client'
import { toast } from "sonner";
import { useEffect } from "react";
import { getConfiguredHostname } from "./actions";
import { ExternalLink, Link } from "lucide-react";
import { Button } from "@/components/ui/button";
export default function HostnameCheck() {
const checkForCorrectHostname = async () => {
const configuredDomain = await getConfiguredHostname();
if (configuredDomain.status === 'success') {
const hostname = window.location.hostname;
const serverParamHostname = configuredDomain.data;
if (serverParamHostname && serverParamHostname !== hostname) {
toast.warning(`QuickStack is configured to run on a different domain. Please open the application on https://${serverParamHostname}`, {
duration: 10000,
action: {
label: <Button variant="ghost"><ExternalLink /> open</Button>,
onClick: () => {
window.open(`https://${serverParamHostname}`, '_blank');
}
}
});
}
}
}
useEffect(() => {
checkForCorrectHostname();
});
return <></>;
}

View File

@@ -1,28 +0,0 @@
'use client'
import { Button } from "@/components/ui/button";
import ProjectPage from "../../app/projects/project-page";
import paramService, { ParamService } from "@/server/services/param.service";
import { cookies } from "next/headers";
import { toast } from "sonner";
import { usePathname } from "next/navigation";
import { useRouter } from "next/router";
import { useEffect } from "react";
export default function HostnameCheck({ serverParamHostname }: { serverParamHostname?: string }) {
useEffect(() => {
const hostname = window.location.hostname;
if (serverParamHostname && serverParamHostname !== hostname) {
toast.warning(`QuickStack is configured to run on a different domain. Please open the application on https://${serverParamHostname}`, {
duration: 10000,
action: {
label: 'Open',
onClick: () => {
window.location.href = `https://${serverParamHostname}`;
}
}
});
}
}, [serverParamHostname]);
return <></>;
}