main
|
Last change
on this file since 6270fa4 was 6270fa4, checked in by Tome <gjorgievtome@…>, 5 months ago |
|
Trim whitespace from username and email during authentication and registration
|
-
Property mode
set to
100644
|
|
File size:
788 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 trimmedUsername = username.trim();
|
|---|
| 16 | const trimmedEmail = email.trim();
|
|---|
| 17 | const result = await drizzleQueries.createUser(c.db, trimmedUsername, trimmedEmail, passwordHash);
|
|---|
| 18 |
|
|---|
| 19 | if(!result) throw Abort();
|
|---|
| 20 |
|
|---|
| 21 | return { success: true };
|
|---|
| 22 | } |
|---|
Note:
See
TracBrowser
for help on using the repository browser.