This commit is contained in:
2026-03-12 12:50:30 +00:00
parent a34fd3aa20
commit ee62ac8f54
18 changed files with 258 additions and 93 deletions
+1
View File
@@ -1,4 +1,5 @@
import "@/src/styles/globals.css";
import "prism-themes/themes/prism-dracula.css";
import type { AppProps } from "next/app";
import { createContext } from "react";
import { PagePropsType, TurboCIAdminAppContextType } from "../types";
+25 -1
View File
@@ -1,6 +1,8 @@
import Main from "@/src/components/pages/admin/settings";
import { NSQLITE_TURBOCI_ADMIN_USERS } from "@/src/db/types";
import defaultAdminProps from "@/src/functions/pages/admin/default-admin-props";
import Layout from "@/src/layouts/admin";
import NSQLite from "@moduletrace/nsqlite";
import { GetServerSideProps } from "next";
export default function AdminSettings() {
@@ -12,5 +14,27 @@ export default function AdminSettings() {
}
export const getServerSideProps: GetServerSideProps = async (ctx) => {
return await defaultAdminProps({ ctx });
return await defaultAdminProps({
ctx,
async propsFn({ user }) {
if (!user.id) {
return `/admin`;
}
const users_res = await NSQLite.select<NSQLITE_TURBOCI_ADMIN_USERS>(
{
table: "users",
targetId: user.id,
},
);
if (!users_res.singleRes?.id) {
return `/admin/users`;
}
return {
deployment_user: users_res.singleRes,
};
},
});
};
@@ -29,6 +29,10 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
},
);
if (!users_res.singleRes?.id) {
return `/admin/users`;
}
return {
deployment_user: users_res.singleRes,
};
+17 -6
View File
@@ -73,7 +73,7 @@ export default async function handler(
email,
password: new_user_password,
is_super_admin: user?.id ? 0 : 1,
username: slugify(username),
username: username ? slugify(username) : undefined,
},
],
table: "users",
@@ -90,20 +90,31 @@ export default async function handler(
(typeof NSQLiteTables)[number]
>({
table: "users",
query: {
query: {
is_super_admin: { value: "1" },
},
},
targetId: new_user_id,
});
const newly_inserted_user = newly_inserted_user_res.singleRes;
if (!newly_inserted_user?.id) {
console.log("newly_inserted_user_res", newly_inserted_user_res);
throw new Error(`Couldn't Find Newly inserted user.`);
}
if (user?.id && !newly_inserted_user.username) {
const newly_inserted_user_res = await NSQLite.delete<
NSQLITE_TURBOCI_ADMIN_USERS,
(typeof NSQLiteTables)[number]
>({
table: "users",
targetId: newly_inserted_user?.id,
});
throw new Error(`Couldn't set Newly inserted user username.`);
}
if (user?.id) {
console.log("newly_inserted_user", newly_inserted_user);
await setupDeploymentUser({ user_id: newly_inserted_user.id });
return res.json({