Skip to content

Commit e674e78

Browse files
committed
(auth) completed staff & admin authentication
1 parent 38190e4 commit e674e78

16 files changed

Lines changed: 476 additions & 7 deletions

File tree

api-gateway/src/app.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import cors from 'cors';
33
import healthRoutes from './routes/health';
44
import { patientAuthProxy } from './proxy/patient.auth.proxy';
55
import { patientDataProxy } from './proxy/patient.data.proxy';
6+
import { staffAuthProxy } from './proxy/staff.auth.proxy';
7+
import { staffDataProxy } from './proxy/staff.data.proxy';
68
import { authenticate } from './middlewares/auth.middleware';
79
import { requirePatientSelf } from './middlewares/patient.guard';
810

@@ -15,8 +17,10 @@ app.use('/health', healthRoutes);
1517

1618
// 🔓 PUBLIC auth (NO JWT)
1719
app.use('/patients/public', patientAuthProxy);
18-
1920
// 🔐 PROTECTED patient data
2021
app.use('/patients', authenticate, requirePatientSelf, patientDataProxy);
2122

23+
app.use('/staff/public', staffAuthProxy);
24+
app.use('/staff', authenticate, staffDataProxy);
25+
2226
export default app;

api-gateway/src/middlewares/auth.middleware.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ import { error } from 'node:console';
55
export interface AuthenticatedRequest extends Request {
66
user?: {
77
sub: string;
8-
role: string;
9-
type: 'PATIENT' | 'STAFF';
8+
type: 'PATIENT' | 'STAFF' | 'ADMIN';
9+
10+
// present for STAFF / PATIENT
11+
role?: string;
12+
13+
// present for STAFF
14+
job_title?: 'HEAD_STAFF' | 'STAFF';
15+
department?: string;
1016
};
1117
}
1218

Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { createProxyMiddleware } from 'http-proxy-middleware';
22

3-
export const staffProxy = createProxyMiddleware({
3+
export const staffAuthProxy = createProxyMiddleware({
44
target: 'http://localhost:3002',
55
changeOrigin: true,
6+
7+
// /staff/public/auth/login → /auth/login
68
pathRewrite: {
7-
'^/staff': '',
9+
'^/staff/public': '',
810
},
911
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { createProxyMiddleware } from 'http-proxy-middleware';
2+
3+
export const staffDataProxy = createProxyMiddleware({
4+
target: 'http://localhost:3002',
5+
changeOrigin: true,
6+
7+
// /staff/* → /staff/*
8+
pathRewrite: (path) => `/staff${path}`,
9+
});

docs/decisions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Reason:
4848

4949
| Purpose | Technology | Library |
5050
| ------------- | ---------- | ----------- |
51-
| PostgreSQL | SQL | pg + Prisma |
51+
| PostgreSQL | SQL | pg |
5252
| MongoDB | NoSQL | mongoose |
5353
| Redis | Cache | ioredis |
5454
| Message Queue | RabbitMQ | amqplib |

frontend/.gitkeep

Whitespace-only changes.

pnpm-lock.yaml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

services/staff-service/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@
1515
"packageManager": "pnpm@10.28.2",
1616
"dependencies": {
1717
"@prisma/client": "^7.3.0",
18+
"bcrypt": "^6.0.0",
1819
"express": "^5.2.1",
20+
"jsonwebtoken": "^9.0.3",
1921
"prisma": "^7.3.0"
2022
},
2123
"devDependencies": {
24+
"@types/bcrypt": "^6.0.0",
2225
"@types/express": "^5.0.6",
26+
"@types/jsonwebtoken": "^9.0.10",
2327
"@types/node": "^25.1.0",
2428
"dotenv": "^17.2.3",
2529
"tsx": "^4.21.0",

services/staff-service/src/app.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import express from 'express';
2-
import healthRouter from './routes/health.js';
2+
import healthRouter from './routes/health';
3+
import authRouter from './modules/auth/auth.routes';
4+
import staffRouter from './modules/staff/staff.routes';
35

46
const app = express();
57
app.use(express.json());
68

79
app.use('/health', healthRouter);
10+
app.use('/auth', authRouter);
11+
12+
app.use('/staff', staffRouter);
813

914
export default app;

services/staff-service/src/db.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import 'dotenv/config';
2+
import { Pool } from 'pg';
3+
4+
if (!process.env.DATABASE_URL) {
5+
throw new Error('DATABASE_URL is not defined for staff-service');
6+
}
7+
8+
export const pool = new Pool({
9+
connectionString: process.env.DATABASE_URL,
10+
});
11+
12+
pool.on('connect', () => {
13+
console.log('Staff Service DB connected');
14+
});

0 commit comments

Comments
 (0)