fix: Client and server validation differ for subdomains (#9468)

* fix: Client and server validation differ for subdomains

* Validation message

* Lower min subdomain length to 2
This commit is contained in:
Tom Moor
2025-06-18 16:50:17 -04:00
committed by GitHub
parent a3b3e9e0be
commit ca5c51a712
3 changed files with 24 additions and 6 deletions

View File

@@ -10,6 +10,7 @@ import { ThemeProvider, useTheme } from "styled-components";
import { buildDarkTheme, buildLightTheme } from "@shared/styles/theme";
import { CustomTheme, TOCPosition, TeamPreference } from "@shared/types";
import { getBaseDomain } from "@shared/utils/domains";
import { TeamValidation } from "@shared/validations";
import Button from "~/components/Button";
import ButtonLink from "~/components/ButtonLink";
import DefaultCollectionInputSelect from "~/components/DefaultCollectionInputSelect";
@@ -322,8 +323,12 @@ function Details() {
value={subdomain || ""}
onChange={handleSubdomainChange}
autoComplete="off"
minLength={4}
maxLength={32}
minLength={TeamValidation.minSubdomainLength}
maxLength={
isCloudHosted
? TeamValidation.maxSubdomainLength
: TeamValidation.maxSubdomainSelfHostedLength
}
/>
</SettingRow>
<SettingRow

View File

@@ -90,10 +90,14 @@ class Team extends ParanoidModel<
@IsLowercase
@Unique
@Length({
min: 2,
max: env.isCloudHosted ? 32 : 255,
msg: `subdomain must be between 2 and ${
env.isCloudHosted ? 32 : 255
min: TeamValidation.minSubdomainLength,
max: env.isCloudHosted
? TeamValidation.maxSubdomainLength
: TeamValidation.maxSubdomainSelfHostedLength,
msg: `subdomain must be between ${TeamValidation.minSubdomainLength} and ${
env.isCloudHosted
? TeamValidation.maxSubdomainLength
: TeamValidation.maxSubdomainSelfHostedLength
} characters`,
})
@Is({

View File

@@ -98,6 +98,15 @@ export const TeamValidation = {
/** The maximum length of the team description */
maxDescriptionLength: 1000,
/** The minimum length of the team subdomain */
minSubdomainLength: 2,
/** The maximum length of the team subdomain for cloud */
maxSubdomainLength: 32,
/** The maximum length of the team subdomain for self-hosted */
maxSubdomainSelfHostedLength: 255,
};
export const UserValidation = {