Updates
This commit is contained in:
@@ -6,6 +6,7 @@ import { APIResponseObject } from "@moduletrace/datasquirel/dist/package-shared/
|
||||
import NSQLite from "@moduletrace/nsqlite";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import userAuth from "@/src/utils/user-auth";
|
||||
import { slugify } from "@/src/exports/client-exports";
|
||||
|
||||
export default async function handler(
|
||||
req: NextApiRequest,
|
||||
@@ -23,6 +24,10 @@ export default async function handler(
|
||||
|
||||
const { new_user } = req.body as APIReqObject;
|
||||
|
||||
if (user?.id && !new_user?.username?.match(/^[a-z0-9\-]{3,}$/)) {
|
||||
throw new Error(`Please pass a valid username`);
|
||||
}
|
||||
|
||||
if (!new_user) {
|
||||
throw new Error(`No new User Object Passed!`);
|
||||
}
|
||||
@@ -52,7 +57,7 @@ export default async function handler(
|
||||
});
|
||||
}
|
||||
|
||||
const { first_name, email, last_name, password } = new_user;
|
||||
const { first_name, email, last_name, password, username } = new_user;
|
||||
|
||||
const new_user_password = hashPassword({ password });
|
||||
|
||||
@@ -67,6 +72,7 @@ export default async function handler(
|
||||
email,
|
||||
password: new_user_password,
|
||||
is_super_admin: user?.id ? 0 : 1,
|
||||
username: slugify(username),
|
||||
},
|
||||
],
|
||||
table: "users",
|
||||
|
||||
Reference in New Issue
Block a user