diff options
| author | Mohamed Bassem <me@mbassem.com> | 2025-06-21 10:44:53 +0000 |
|---|---|---|
| committer | Mohamed Bassem <me@mbassem.com> | 2025-06-21 10:45:36 +0000 |
| commit | f1f665f89cba21d4d448d27471d01a4d78a184ff (patch) | |
| tree | 61a730db28e71bdfad5d27af976f5585fe637daa /packages | |
| parent | 6c0bcca1d5f4c72d128e8ae0298e2e896d2b2e30 (diff) | |
| download | karakeep-f1f665f89cba21d4d448d27471d01a4d78a184ff.tar.zst | |
fix: Fix oauth creation failure due to missing UserSettings table. Fixes #1583
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/trpc/routers/users.ts | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/packages/trpc/routers/users.ts b/packages/trpc/routers/users.ts index 3813387f..87923f94 100644 --- a/packages/trpc/routers/users.ts +++ b/packages/trpc/routers/users.ts @@ -31,13 +31,19 @@ import { router, } from "../index"; -export async function createUser( - input: z.infer<typeof zSignUpSchema>, - ctx: Context, - role?: "user" | "admin", +export async function createUserRaw( + db: Context["db"], + input: { + name: string; + email: string; + password?: string; + salt?: string; + role?: "user" | "admin"; + emailVerified?: Date | null; + }, ) { - return ctx.db.transaction(async (trx) => { - let userRole = role; + return await db.transaction(async (trx) => { + let userRole = input.role; if (!userRole) { const [{ count: userCount }] = await trx .select({ count: count() }) @@ -45,30 +51,31 @@ export async function createUser( userRole = userCount == 0 ? "admin" : "user"; } - const salt = generatePasswordSalt(); try { - const result = await trx + const [result] = await trx .insert(users) .values({ name: input.name, email: input.email, - password: await hashPassword(input.password, salt), - salt, + password: input.password, + salt: input.salt, role: userRole, + emailVerified: input.emailVerified, }) .returning({ id: users.id, name: users.name, email: users.email, role: users.role, + emailVerified: users.emailVerified, }); // Insert user settings for the new user await trx.insert(userSettings).values({ - userId: result[0].id, + userId: result.id, }); - return result[0]; + return result; } catch (e) { if (e instanceof SqliteError) { if (e.code == "SQLITE_CONSTRAINT_UNIQUE") { @@ -86,6 +93,21 @@ export async function createUser( }); } +export async function createUser( + input: z.infer<typeof zSignUpSchema>, + ctx: Context, + role?: "user" | "admin", +) { + const salt = generatePasswordSalt(); + return await createUserRaw(ctx.db, { + name: input.name, + email: input.email, + password: await hashPassword(input.password, salt), + salt, + role, + }); +} + export const usersAppRouter = router({ create: publicProcedure .input(zSignUpSchema) |
