added hostname check component

This commit is contained in:
biersoeckli
2024-11-22 12:26:37 +00:00
parent aaaeb0f429
commit c061ccae3e
4 changed files with 42 additions and 4 deletions

View File

@@ -3,6 +3,7 @@
import { AuthFormInputSchema, authFormInputSchemaZod, RegisterFormInputSchema, registgerFormInputSchemaZod } from "@/model/auth-form";
import { SuccessActionResult } from "@/model/server-action-error-return.model";
import { ServiceException } from "@/model/service.exception.model";
import paramService, { ParamService } from "@/server/services/param.service";
import quickStackService from "@/server/services/qs.service";
import userService from "@/server/services/user.service";
import { saveFormAction } from "@/server/utils/action-wrapper.utils";
@@ -18,6 +19,10 @@ export const registerUser = async (prevState: any, inputData: RegisterFormInputS
await quickStackService.createOrUpdateCertIssuer(validatedData.email);
if (validatedData.qsHostname) {
const url = new URL(validatedData.qsHostname.includes('://') ? validatedData.qsHostname : `https://${validatedData.qsHostname}`);
await paramService.save({
name: ParamService.QS_SERVER_HOSTNAME,
value: url.hostname
});
await quickStackService.createOrUpdateIngress(url.hostname);
return new SuccessActionResult(undefined, 'QuickStack is now available at: ' + url.href);
}

View File

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

View File

@@ -0,0 +1,28 @@
'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 <></>;
}

View File

@@ -7,7 +7,7 @@ export const authFormInputSchemaZod = z.object({
export type AuthFormInputSchema = z.infer<typeof authFormInputSchemaZod>;
export const registgerFormInputSchemaZod = authFormInputSchemaZod.merge(z.object({
qsHostname: z.string().url().optional(),
qsHostname: z.string().trim().optional(),
}));
export type RegisterFormInputSchema = z.infer<typeof registgerFormInputSchemaZod>;