feat(frontend): sidebar migration started

This commit is contained in:
2025-09-23 20:54:28 -05:00
parent cb2e6252e0
commit bee436d341
57 changed files with 2608 additions and 359 deletions

View File

@@ -16,7 +16,7 @@ export const systemAdminRole = async (userId: string) => {
},
{
userId: userId,
module: "system",
module: "admin",
role: "systemAdmin",
},
{

View File

@@ -25,7 +25,6 @@ const registerSchema = z.object({
router.post("/", async (req: Request, res: Response) => {
// check if we are the first user so we can add as system admin to all modules
const totalUsers = await db.select({ count: count() }).from(user);
console.log(totalUsers[0].count);
try {
// Parse + validate incoming JSON against Zod schema
const validated = registerSchema.parse(req.body);

View File

@@ -1,9 +1,11 @@
import type { Express, Request, Response } from "express";
import me from "./me.js";
import register from "./register.js";
import userRoles from "./userroles.js";
import { requireAuth } from "../../../pkg/middleware/authMiddleware.js";
export const setupAuthRoutes = (app: Express, basePath: string) => {
app.use(basePath + "/api/user/me", requireAuth(), me);
app.use(basePath + "/api/user/register", register);
app.use(basePath + "/api/user/roles", requireAuth(), userRoles);
};

View File

@@ -0,0 +1,32 @@
import { Router } from "express";
import type { Request, Response } from "express";
import z from "zod";
import { db } from "../../../pkg/db/db.js";
import { userRoles } from "../../../pkg/db/schema/user_roles.js";
import { DrizzleError, eq } from "drizzle-orm";
import { requireAuth } from "../../../pkg/middleware/authMiddleware.js";
import { auth } from "../../../pkg/auth/auth.js";
import { authClient } from "../../../pkg/auth/auth-client.js";
const router = Router();
router.get("/", async (req: Request, res: Response) => {
const userID = req.user?.id || "";
try {
// get the roles the user has
const roles = await db
.select()
.from(userRoles)
.where(eq(userRoles.userId, userID));
return res.status(200).json({ success: true, data: roles });
} catch (err) {
if (err instanceof DrizzleError && err.cause) {
return res
.status(400)
.json({ message: "db error", error: err.cause });
}
}
});
export default router;