mirror of
https://github.com/ajnart/homarr.git
synced 2026-02-27 17:00:54 +01:00
* wip: improve user preferences * wip: fix translations and add user danger zone * feat: add user delete button to danger zone * fix: test not working * refactor: add access checks for user edit page, improve not found behaviour, change user preference link in avatar menu to correct link * fix: remove invalid bg for container * chore: address pull request feedback
81 lines
1.9 KiB
TypeScript
81 lines
1.9 KiB
TypeScript
import { z } from "zod";
|
|
|
|
const usernameSchema = z.string().min(3).max(255);
|
|
const passwordSchema = z.string().min(8).max(255);
|
|
|
|
const createUserSchema = z
|
|
.object({
|
|
username: usernameSchema,
|
|
password: passwordSchema,
|
|
confirmPassword: z.string(),
|
|
email: z.string().email().optional(),
|
|
})
|
|
.refine((data) => data.password === data.confirmPassword, {
|
|
path: ["confirmPassword"],
|
|
message: "Passwords do not match",
|
|
});
|
|
|
|
const initUserSchema = createUserSchema;
|
|
|
|
const signInSchema = z.object({
|
|
name: z.string(),
|
|
password: z.string(),
|
|
});
|
|
|
|
const registrationSchema = z
|
|
.object({
|
|
username: usernameSchema,
|
|
password: passwordSchema,
|
|
confirmPassword: z.string(),
|
|
})
|
|
.refine((data) => data.password === data.confirmPassword, {
|
|
path: ["confirmPassword"],
|
|
message: "Passwords do not match",
|
|
});
|
|
|
|
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(),
|
|
password: passwordSchema,
|
|
confirmPassword: z.string(),
|
|
})
|
|
.refine((data) => data.password === data.confirmPassword, {
|
|
path: ["confirmPassword"],
|
|
message: "Passwords do not match",
|
|
});
|
|
|
|
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,
|
|
};
|