mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 23:27:35 +00:00
Improve /complete-account/signup body schema
This commit is contained in:
@@ -48,22 +48,3 @@ export const SecretNameSchema = BaseSecretNameSchema.refine(
|
|||||||
)
|
)
|
||||||
.refine((el) => !el.includes(":"), "Secret name cannot contain colon.")
|
.refine((el) => !el.includes(":"), "Secret name cannot contain colon.")
|
||||||
.refine((el) => !el.includes("/"), "Secret name cannot contain forward slash.");
|
.refine((el) => !el.includes("/"), "Secret name cannot contain forward slash.");
|
||||||
|
|
||||||
const DefaultOrgSchema = z.object({
|
|
||||||
useDefaultOrg: z.literal(true)
|
|
||||||
});
|
|
||||||
|
|
||||||
const CustomOrgSchema = z.object({
|
|
||||||
useDefaultOrg: z.literal(false),
|
|
||||||
organizationName: GenericResourceNameSchema
|
|
||||||
});
|
|
||||||
|
|
||||||
export const OrganizationInputSchema = z.preprocess(
|
|
||||||
(data) => {
|
|
||||||
if (typeof data === "object" && data && "useDefaultOrg" in data === false) {
|
|
||||||
return { ...data, useDefaultOrg: false };
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
},
|
|
||||||
z.discriminatedUnion("useDefaultOrg", [DefaultOrgSchema, CustomOrgSchema])
|
|
||||||
);
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { UsersSchema } from "@app/db/schemas";
|
|||||||
import { getConfig } from "@app/lib/config/env";
|
import { getConfig } from "@app/lib/config/env";
|
||||||
import { ForbiddenRequestError } from "@app/lib/errors";
|
import { ForbiddenRequestError } from "@app/lib/errors";
|
||||||
import { authRateLimit } from "@app/server/config/rateLimiter";
|
import { authRateLimit } from "@app/server/config/rateLimiter";
|
||||||
import { OrganizationInputSchema } from "@app/server/lib/schemas";
|
import { GenericResourceNameSchema } from "@app/server/lib/schemas";
|
||||||
import { getServerCfg } from "@app/services/super-admin/super-admin-service";
|
import { getServerCfg } from "@app/services/super-admin/super-admin-service";
|
||||||
import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";
|
import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";
|
||||||
|
|
||||||
@@ -106,7 +106,23 @@ export const registerSignupRouter = async (server: FastifyZodProvider) => {
|
|||||||
attributionSource: z.string().trim().optional(),
|
attributionSource: z.string().trim().optional(),
|
||||||
password: z.string()
|
password: z.string()
|
||||||
})
|
})
|
||||||
.and(OrganizationInputSchema),
|
.and(
|
||||||
|
z.preprocess(
|
||||||
|
(data) => {
|
||||||
|
if (typeof data === "object" && data && "useDefaultOrg" in data === false) {
|
||||||
|
return { ...data, useDefaultOrg: false };
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
z.discriminatedUnion("useDefaultOrg", [
|
||||||
|
z.object({ useDefaultOrg: z.literal(true) }),
|
||||||
|
z.object({
|
||||||
|
useDefaultOrg: z.literal(false),
|
||||||
|
organizationName: GenericResourceNameSchema
|
||||||
|
})
|
||||||
|
])
|
||||||
|
)
|
||||||
|
),
|
||||||
response: {
|
response: {
|
||||||
200: z.object({
|
200: z.object({
|
||||||
message: z.string(),
|
message: z.string(),
|
||||||
|
|||||||
Reference in New Issue
Block a user