Add documentation, clean repository templating

This commit is contained in:
2025-07-18 01:38:43 -04:00
parent 1a503d818b
commit 4f8402c5e6
33 changed files with 8178 additions and 152 deletions

View File

@@ -0,0 +1,59 @@
import { z } from "zod";
import bcrypt from "bcryptjs";
import { TRPCError } from "@trpc/server";
import { eq } from "drizzle-orm";
import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";
import { users } from "~/server/db/schema";
export const authRouter = createTRPCRouter({
register: publicProcedure
.input(
z.object({
name: z.string().min(1, "Name is required"),
email: z.string().email("Invalid email address"),
password: z.string().min(6, "Password must be at least 6 characters"),
}),
)
.mutation(async ({ ctx, input }) => {
const { name, email, password } = input;
// Check if user already exists
const existingUser = await ctx.db.query.users.findFirst({
where: eq(users.email, email),
});
if (existingUser) {
throw new TRPCError({
code: "CONFLICT",
message: "User with this email already exists",
});
}
// Hash password
const hashedPassword = await bcrypt.hash(password, 12);
try {
// Create user
const [newUser] = await ctx.db
.insert(users)
.values({
name,
email,
password: hashedPassword,
})
.returning({
id: users.id,
name: users.name,
email: users.email,
});
return newUser;
} catch (error) {
throw new TRPCError({
code: "INTERNAL_SERVER_ERROR",
message: "Failed to create user",
});
}
}),
});