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 | |
|---|
| 1 | import * as drizzleQueries from "../../../database/drizzle/queries/users";
|
|---|
| 2 | import { ctx } from "../../../server/telefunc/ctx";
|
|---|
| 3 | import { Abort } from "telefunc";
|
|---|
| 4 | import bcrypt from "bcrypt";
|
|---|
| 5 |
|
|---|
| 6 | export 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.