bug fixed
This commit is contained in:
parent
299498ffa6
commit
863bcc3838
|
@ -49,12 +49,18 @@ export default async function postUser(
|
||||||
|
|
||||||
// Check username (if email was disabled)
|
// Check username (if email was disabled)
|
||||||
const checkUsername = RegExp("^[a-z0-9_-]{3,31}$");
|
const checkUsername = RegExp("^[a-z0-9_-]{3,31}$");
|
||||||
if (!emailEnabled && !checkUsername.test(body.username?.toLowerCase() || ""))
|
|
||||||
|
const autoGeneratedUsername = "user" + Math.round(Math.random() * 1000000000);
|
||||||
|
|
||||||
|
if (body.username && !checkUsername.test(body.username?.toLowerCase()))
|
||||||
return {
|
return {
|
||||||
response:
|
response:
|
||||||
"Username has to be between 3-30 characters, no spaces and special characters are allowed.",
|
"Username has to be between 3-30 characters, no spaces and special characters are allowed.",
|
||||||
status: 400,
|
status: 400,
|
||||||
};
|
};
|
||||||
|
else if (!body.username) {
|
||||||
|
body.username = autoGeneratedUsername;
|
||||||
|
}
|
||||||
|
|
||||||
const checkIfUserExists = await prisma.user.findFirst({
|
const checkIfUserExists = await prisma.user.findFirst({
|
||||||
where: {
|
where: {
|
||||||
|
@ -89,7 +95,8 @@ export default async function postUser(
|
||||||
data: {
|
data: {
|
||||||
name: body.name,
|
name: body.name,
|
||||||
username: emailEnabled
|
username: emailEnabled
|
||||||
? autoGeneratedUsername
|
? (body.username as string).toLowerCase().trim() ||
|
||||||
|
autoGeneratedUsername
|
||||||
: (body.username as string).toLowerCase().trim(),
|
: (body.username as string).toLowerCase().trim(),
|
||||||
email: emailEnabled ? body.email?.toLowerCase().trim() : undefined,
|
email: emailEnabled ? body.email?.toLowerCase().trim() : undefined,
|
||||||
password: hashedPassword,
|
password: hashedPassword,
|
||||||
|
|
Ŝarĝante…
Reference in New Issue