feat(frontend): sidebar migration started
This commit is contained in:
@@ -16,7 +16,7 @@ export const systemAdminRole = async (userId: string) => {
|
||||
},
|
||||
{
|
||||
userId: userId,
|
||||
module: "system",
|
||||
module: "admin",
|
||||
role: "systemAdmin",
|
||||
},
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
32
app/src/internal/auth/routes/userroles.ts
Normal file
32
app/src/internal/auth/routes/userroles.ts
Normal 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;
|
||||
Reference in New Issue
Block a user