Files
homarr/packages/api/src/router/user.ts
Meier Lukas fa19966fcc chore: restructure packages of the project (#7)
* chore: restructure validation package

* chore: move zod only to validation package

* chore: rename packages from alparr to homarr

* chore: move mantine core, dates and icons library to ui package, move most other mantine packages to seperate packages for further customization and centralization

* chore: fix formatting

* fix: wrong typecheck command in turbo generator

* chore: fix formatting

* chore: address pull request feedback

* chore: fix ci check issues
2024-01-02 14:18:37 +01:00

40 lines
1010 B
TypeScript

import "server-only";
import { TRPCError } from "@trpc/server";
import { createSalt, hashPassword } from "@homarr/auth";
import { createId, schema } from "@homarr/db";
import { validation } from "@homarr/validation";
import { createTRPCRouter, publicProcedure } from "../trpc";
export const userRouter = createTRPCRouter({
initUser: publicProcedure
.input(validation.user.init)
.mutation(async ({ ctx, input }) => {
const firstUser = await ctx.db.query.users.findFirst({
columns: {
id: true,
},
});
if (firstUser) {
throw new TRPCError({
code: "FORBIDDEN",
message: "User already exists",
});
}
const salt = await createSalt();
const hashedPassword = await hashPassword(input.password, salt);
const userId = createId();
await ctx.db.insert(schema.users).values({
id: userId,
name: input.username,
password: hashedPassword,
salt,
});
}),
});