🐛 Fix schema validation for user creation

This commit is contained in:
Manuel
2023-07-31 22:36:43 +02:00
parent 061ae1ae6c
commit 961b8024ab
3 changed files with 22 additions and 23 deletions

View File

@@ -4,6 +4,7 @@ import { z } from 'zod';
import { hashPassword } from '~/utils/security';
import {
colorSchemeParser,
createNewUserSchema,
signUpFormSchema,
updateSettingsValidationSchema,
} from '~/validations/user';
@@ -188,29 +189,21 @@ export const userRouter = createTRPCRouter({
nextCursor,
};
}),
createUser: publicProcedure
.input(
z.object({
username: z.string(),
email: z.string().email().optional(),
password: z.string().min(8).max(100),
})
)
.mutation(async ({ ctx, input }) => {
const salt = bcrypt.genSaltSync(10);
const hashedPassword = hashPassword(input.password, salt);
await ctx.prisma.user.create({
data: {
name: input.username,
email: input.email,
password: hashedPassword,
salt: salt,
settings: {
create: {},
},
createUser: publicProcedure.input(createNewUserSchema).mutation(async ({ ctx, input }) => {
const salt = bcrypt.genSaltSync(10);
const hashedPassword = hashPassword(input.password, salt);
await ctx.prisma.user.create({
data: {
name: input.username,
email: input.email,
password: hashedPassword,
salt: salt,
settings: {
create: {},
},
});
}),
},
});
}),
deleteUser: publicProcedure
.input(