source: pages/auth/register/register.telefunc.ts@ 83fb5e2

main
Last change on this file since 83fb5e2 was 83fb5e2, checked in by Tome <gjorgievtome@…>, 7 months ago

fix returns and add checks

  • Property mode set to 100644
File size: 690 bytes
Line 
1import * as drizzleQueries from "../../../database/drizzle/queries/users";
2import { ctx } from "../../../server/telefunc/ctx";
3import { Abort } from "telefunc";
4import bcrypt from "bcrypt";
5
6export async function registerNewUser({ username, email, password }
7 : { username: string; email: string; password: string }) {
8 const c = ctx();
9
10 if (c.session?.user?.id) throw Abort();
11
12 if(!username || !email || !password) throw Abort();
13
14 const passwordHash = await bcrypt.hash(password, 8);
15 const result = await drizzleQueries.createUser(c.db, username, email, passwordHash);
16
17 if(!result) throw Abort();
18
19 return { success: true };
20}
Note: See TracBrowser for help on using the repository browser.