Skip to content

Commit 457b92b

Browse files
committed
patient:profile management
1 parent 8920207 commit 457b92b

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

api-gateway/src/app.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,18 @@ app.use('/health', healthRoutes);
2525
app.use('/patients/public', patientAuthProxy);
2626

2727
// PATIENT self routes
28-
app.use('/patients', authenticate, requirePatientSelf, patientDataProxy);
29-
28+
app.use(
29+
'/patients',
30+
authenticate,
31+
requirePatientSelf,
32+
(req: any, _res, next) => {
33+
if (req.user?.sub) {
34+
req.headers['x-user-id'] = String(req.user.sub);
35+
}
36+
next();
37+
},
38+
patientDataProxy
39+
);
3040
// STAFF auth
3141
app.use('/staff/public', staffAuthProxy);
3242
app.use('/staff', authenticate, staffDataRouter);

api-gateway/src/middlewares/patient.guard.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,22 @@ export function requirePatientSelf(
1010
return res.status(401).json({ error: 'Unauthorized' });
1111
}
1212

13-
// URL will be /:id after /patients is stripped
1413
const patientIdFromPath = req.path.split('/')[1];
1514

1615
if (!patientIdFromPath) {
1716
return res.status(400).json({ error: 'Invalid patient path' });
1817
}
1918

19+
/**
20+
* Allow /patients/me directly
21+
*/
22+
if (patientIdFromPath === 'me') {
23+
return next();
24+
}
25+
26+
/**
27+
* Protect /patients/:id
28+
*/
2029
if (req.user.sub !== patientIdFromPath) {
2130
return res.status(403).json({ error: 'Access denied' });
2231
}

0 commit comments

Comments
 (0)