Fix "Domain was somehow not a valid URL"

This commit is contained in:
Konstantin Wohlwend 2024-12-09 23:58:03 -08:00
parent 5cfc65c9ca
commit b8a7e911ea
2 changed files with 12 additions and 5 deletions

View File

@ -4,6 +4,7 @@ import { InputField, SwitchField } from "@/components/form-fields";
import { SettingCard, SettingSwitch } from "@/components/settings";
import { AdminDomainConfig, AdminProject } from "@stackframe/stack";
import { urlSchema } from "@stackframe/stack-shared/dist/schema-fields";
import { isValidUrl } from "@stackframe/stack-shared/dist/utils/urls";
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, ActionCell, ActionDialog, Alert, Button, Table, TableBody, TableCell, TableHead, TableHeader, TableRow, Typography } from "@stackframe/stack-ui";
import React from "react";
import * as yup from "yup";
@ -104,10 +105,11 @@ function EditDialog(props: {
/>
{props.type === 'create' &&
urlSchema.url().defined().isValidSync('https://' + form.watch('domain')) &&
!((form.watch('domain') as any)?.startsWith('www.')) && (
isValidUrl('https://' + form.watch('domain')) &&
!((form.watch('domain') as any)?.startsWith('www.')) &&
isValidUrl('https://www.' + form.watch('domain')) && (
<SwitchField
label={`Also add www.${form.watch('domain') as any ?? ''} to the trusted domains`}
label={`Also add www.${form.watch('domain') as any ?? ''} as a trusted domain`}
name="addWww"
control={form.control}
/>

View File

@ -1,5 +1,5 @@
import { ProjectsCrud } from "../interface/crud/projects";
import { StackAssertionError } from "../utils/errors";
import { StackAssertionError, captureError } from "../utils/errors";
import { isLocalhost } from "../utils/urls";
export type ProductionModeError = {
@ -23,10 +23,15 @@ export function getProductionModeErrors(project: ProjectsCrud["Admin"]["Read"]):
try {
url = new URL(domain);
} catch (e) {
throw new StackAssertionError("Domain was somehow not a valid URL; we should've caught this when setting the domain in the first place", {
captureError("production-mode-domain-not-valid", new StackAssertionError("Domain was somehow not a valid URL; we should've caught this when setting the domain in the first place", {
domain,
projectId: project
}));
errors.push({
message: "Trusted domain is not a valid URL: " + domain,
relativeFixUrl: domainsFixUrl,
});
continue;
}
if (isLocalhost(url)) {