auto assign username upon registration

This commit is contained in:
daniel31x13
2024-05-13 00:27:29 -04:00
parent 65b29830f0
commit 341154e928
5 changed files with 20 additions and 117 deletions
+7 -2
View File
@@ -72,6 +72,9 @@ export default async function postUser(
});
if (!checkIfUserExists) {
const autoGeneratedUsername =
"user" + Math.round(Math.random() * 1000000000);
const saltRounds = 10;
const hashedPassword = bcrypt.hashSync(body.password, saltRounds);
@@ -85,7 +88,9 @@ export default async function postUser(
const user = await prisma.user.create({
data: {
name: body.name,
username: (body.username as string).toLowerCase().trim(),
username: emailEnabled
? autoGeneratedUsername
: (body.username as string).toLowerCase().trim(),
email: emailEnabled ? body.email?.toLowerCase().trim() : undefined,
password: hashedPassword,
emailVerified: new Date(),
@@ -121,7 +126,7 @@ export default async function postUser(
data: {
name: body.name,
username: emailEnabled
? undefined
? autoGeneratedUsername
: (body.username as string).toLowerCase().trim(),
email: emailEnabled ? body.email?.toLowerCase().trim() : undefined,
password: hashedPassword,