mirror of
https://github.com/ajnart/homarr.git
synced 2026-02-19 21:17:04 +01:00
* feat: update prettier configuration for print width * chore: apply code formatting to entire repository * fix: remove build files * fix: format issue --------- Co-authored-by: Meier Lukas <meierschlumpf@gmail.com>
81 lines
2.1 KiB
TypeScript
81 lines
2.1 KiB
TypeScript
import { z } from "zod";
|
|
|
|
import { createCustomErrorParams } from "./form/i18n";
|
|
|
|
const usernameSchema = z.string().min(3).max(255);
|
|
const passwordSchema = z.string().min(8).max(255);
|
|
|
|
const confirmPasswordRefine = [
|
|
(data: { password: string; confirmPassword: string }) => data.password === data.confirmPassword,
|
|
{
|
|
path: ["confirmPassword"],
|
|
params: createCustomErrorParams("passwordsDoNotMatch"),
|
|
},
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
] satisfies [(args: any) => boolean, unknown];
|
|
|
|
const createUserSchema = z
|
|
.object({
|
|
username: usernameSchema,
|
|
password: passwordSchema,
|
|
confirmPassword: z.string(),
|
|
email: z.string().email().or(z.string().length(0).optional()),
|
|
})
|
|
.refine(confirmPasswordRefine[0], confirmPasswordRefine[1]);
|
|
|
|
const initUserSchema = createUserSchema;
|
|
|
|
const signInSchema = z.object({
|
|
name: z.string().min(1),
|
|
password: z.string().min(1),
|
|
});
|
|
|
|
const registrationSchema = z
|
|
.object({
|
|
username: usernameSchema,
|
|
password: passwordSchema,
|
|
confirmPassword: z.string(),
|
|
})
|
|
.refine(confirmPasswordRefine[0], confirmPasswordRefine[1]);
|
|
|
|
const registrationSchemaApi = registrationSchema.and(
|
|
z.object({
|
|
inviteId: z.string(),
|
|
token: z.string(),
|
|
}),
|
|
);
|
|
|
|
const editProfileSchema = z.object({
|
|
id: z.string(),
|
|
name: usernameSchema,
|
|
email: z
|
|
.string()
|
|
.email()
|
|
.or(z.literal(""))
|
|
.transform((value) => (value === "" ? null : value))
|
|
.optional()
|
|
.nullable(),
|
|
});
|
|
|
|
const changePasswordSchema = z
|
|
.object({
|
|
previousPassword: z.string().min(1),
|
|
password: passwordSchema,
|
|
confirmPassword: z.string(),
|
|
})
|
|
.refine(confirmPasswordRefine[0], confirmPasswordRefine[1]);
|
|
|
|
const changePasswordApiSchema = changePasswordSchema.and(z.object({ userId: z.string() }));
|
|
|
|
export const userSchemas = {
|
|
signIn: signInSchema,
|
|
registration: registrationSchema,
|
|
registrationApi: registrationSchemaApi,
|
|
init: initUserSchema,
|
|
create: createUserSchema,
|
|
password: passwordSchema,
|
|
editProfile: editProfileSchema,
|
|
changePassword: changePasswordSchema,
|
|
changePasswordApi: changePasswordApiSchema,
|
|
};
|