Update login pipeline. Limit login to only password

This commit is contained in:
2026-09-12 14:20:07 +01:00
parent 4d75af0418
commit 9cfbde9c9a
30 changed files with 145 additions and 1068 deletions
+56 -11
View File
@@ -1,4 +1,8 @@
import type { BUN_SQLITE_WGUI_USERS } from "@/db/types/db";
import type {
BUN_SQLITE_WGUI_USER_TYPES,
BUN_SQLITE_WGUI_USERS,
} from "@/db/types/db";
import { AppData } from "@/src/data/app-data";
import grabUsers from "@/src/functions/backend/db/users/grab-users";
import type { ApiReqParams, TableType } from "@/src/types";
import BunSQLite from "@moduletrace/bun-sqlite";
@@ -6,8 +10,6 @@ import type {
APIResponseObject,
BunextAPIRouteHandler,
} from "@moduletrace/bunext/types";
import { hash } from "bun";
import _ from "lodash";
export const handler: BunextAPIRouteHandler<
APIResponseObject<BUN_SQLITE_WGUI_USERS>
@@ -23,26 +25,69 @@ export const handler: BunextAPIRouteHandler<
},
});
console.log("users_res", users_res);
if (users_res.singleRes?.id) {
return {
success: false,
};
}
let final_insert_data = [
...(body?.insert_data?.map((data) => {
return { ...data, password: hash(data.password || "") };
}) || []),
];
const final_insert_data = await Promise.all(
body?.insert_data?.map(async (data) => {
if (!data.password) {
throw new Error(
`Password is required to create the first user.`,
);
}
return {
...data,
password: await Bun.password.hash(data.password, {
algorithm: "bcrypt",
cost: AppData["HashCost"],
}),
id: 1,
};
}) || [],
);
const POST = await BunSQLite.insert<BUN_SQLITE_WGUI_USERS, TableType>({
table: "users",
data: final_insert_data,
});
return POST;
const new_users_res = await grabUsers({
query: {
sql_query: {
limit: 1,
},
},
});
if (!new_users_res.singleRes?.id) {
throw new Error(
`Couldn't find newly created user record! Try again.`,
);
}
const add_super_admin_user_types = await BunSQLite.insert<
BUN_SQLITE_WGUI_USER_TYPES,
TableType
>({
table: "user_types",
data: [
{
user_type: "super_admin",
user_id: new_users_res.singleRes.id,
},
],
});
console.log("add_super_admin_user_types", add_super_admin_user_types);
return {
...POST,
singleRes: new_users_res.singleRes,
};
} catch (error: any) {
return {
success: false,