diff --git a/backend/src/api/admin.ts b/backend/src/api/admin.ts index cab1487..48b7d9c 100644 --- a/backend/src/api/admin.ts +++ b/backend/src/api/admin.ts @@ -23,8 +23,11 @@ export const adminRouter = (wss: WebSocketServer) => { router.post('/dashboard', requireSuperAdmin, async (req: Request, res: Response) => { const db = await readDB(); - // Sort users by last login (most recent first) + if (!req.user) { + return res.status(401).send('Unauthorized'); + } const currentAdmin = req.user.username; + // Sort users by last login (most recent first) const users = db.users .filter((user) => user.username !== currentAdmin) // Don't show the current admin user in the list .map((user) => ({ diff --git a/backend/src/api/users.ts b/backend/src/api/users.ts index cf1a3aa..6fdae68 100644 --- a/backend/src/api/users.ts +++ b/backend/src/api/users.ts @@ -7,13 +7,10 @@ import jwt from 'jsonwebtoken'; const router = Router(); const saltRounds = 10; -const JWT_SECRET = process.env.JWT_SECRET || 'supersecretkey'; -const JWT_EXPIRES_IN = '7d'; // 7 days +const JWT_SECRET = process.env.JWT_SECRET || 'supersecretkeylkj3lfgdklvadsvi2rsdfh'; function generateToken(user: any) { - return jwt.sign({ username: user.username, isSuper: user.isSuper || false }, JWT_SECRET, { - expiresIn: JWT_EXPIRES_IN - }); + return jwt.sign({ username: user.username, isSuper: user.isSuper || false }, JWT_SECRET); } // JWT auth middleware diff --git a/backend/src/types/express/index.d.ts b/backend/src/types/express/index.d.ts new file mode 100644 index 0000000..5d48c5f --- /dev/null +++ b/backend/src/types/express/index.d.ts @@ -0,0 +1,11 @@ +// backend/src/types/express/index.d.ts +import 'express'; + +declare module 'express' { + export interface Request { + user?: { + username: string; + isSuper: boolean; + }; + } +} diff --git a/backend/tsconfig.json b/backend/tsconfig.json index 2700030..67b7d18 100644 --- a/backend/tsconfig.json +++ b/backend/tsconfig.json @@ -8,5 +8,9 @@ "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true - } + }, + "include": [ + "src", + "src/types/express/index.d.ts" + ] } \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 2cf2622..c6f36db 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,10 +3,11 @@ services: container_name: turn-tracker build: . ports: - - '3001:3001' + - '3821:3001' volumes: - ./data:/data environment: - NODE_ENV=production + - JWT_SECRET=supersecretkeykklvadb13as5lkj3lfgdsvi2rsdfh - SUPER_ADMIN_PASSWORD=l2jkb13as5kldjba6lj4sdf6weh6oo2 restart: unless-stopped