Updates
This commit is contained in:
@@ -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";
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user