show credential pw
This commit is contained in:
@@ -2,8 +2,8 @@ NODE_ENV="development"
|
||||
HOST=0.0.0.0
|
||||
PORT=5000
|
||||
# FRONTEND_URLS=http://localhost:3000,http://192.168.1.8:3000
|
||||
# FRONTEND_URLS=http://localhost:3000
|
||||
FRONTEND_URLS=http://192.168.1.37:3000
|
||||
FRONTEND_URLS=http://localhost:3000
|
||||
# FRONTEND_URLS=http://192.168.1.37:3000
|
||||
SELENIUM_AGENT_BASE_URL=http://localhost:5002
|
||||
JWT_SECRET = 'dentalsecret'
|
||||
DB_HOST=localhost
|
||||
|
||||
@@ -34,6 +34,21 @@ router.get("/", async (req: Request, res: Response): Promise<any> => {
|
||||
}
|
||||
});
|
||||
|
||||
// GET: List all users (admin only)
|
||||
router.get("/list", async (req: Request, res: Response): Promise<any> => {
|
||||
try {
|
||||
if (req.user?.username !== "admin") {
|
||||
return res.status(403).json({ error: "Forbidden" });
|
||||
}
|
||||
const users = await storage.getUsers(1000, 0);
|
||||
const safeUsers = users.map(({ password, ...u }) => u);
|
||||
res.json(safeUsers);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).send("Failed to fetch users");
|
||||
}
|
||||
});
|
||||
|
||||
// GET: User by ID
|
||||
router.get("/:id", async (req: Request, res: Response): Promise<any> => {
|
||||
try {
|
||||
@@ -55,10 +70,18 @@ router.get("/:id", async (req: Request, res: Response): Promise<any> => {
|
||||
});
|
||||
|
||||
// POST: Create new user
|
||||
router.post("/", async (req: Request, res: Response) => {
|
||||
router.post("/", async (req: Request, res: Response): Promise<any> => {
|
||||
try {
|
||||
if (req.user?.username !== "admin") {
|
||||
return res.status(403).json({ error: "Forbidden" });
|
||||
}
|
||||
const input = userCreateSchema.parse(req.body);
|
||||
const newUser = await storage.createUser(input);
|
||||
const existing = await storage.getUserByUsername(input.username as string);
|
||||
if (existing) {
|
||||
return res.status(400).json({ error: "Username already exists" });
|
||||
}
|
||||
const hashed = await hashPassword(input.password as string);
|
||||
const newUser = await storage.createUser({ ...input, password: hashed });
|
||||
const { password, ...safeUser } = newUser;
|
||||
res.status(201).json(safeUser);
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user