source: pages/auth/register/register.telefunc.ts@ 76b980b

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

add telefunctions

  • Property mode set to 100644
File size: 643 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 await drizzleQueries.createUser(c.db, username, email, passwordHash);
16
17 return { success: true };
18}
Note: See TracBrowser for help on using the repository browser.