ShiftSync/api/middleware/auth.js

27 lines
882 B
JavaScript
Raw Normal View History

2026-01-18 04:56:42 +00:00
export const validateMedicationApiKey = (req, res, next) => {
2026-01-18 05:14:04 +00:00
console.log('req: ', req);
console.log('req.headers: ', req.headers);
2026-01-18 04:56:42 +00:00
const authHeader = req.headers['authorization'];
2026-01-18 05:28:35 +00:00
console.log('authHeader: ', authHeader);
2026-01-18 04:56:42 +00:00
const token = authHeader && authHeader.split(' ')[1];
2026-01-18 05:28:35 +00:00
console.log('token: ', token);
2026-01-18 04:56:42 +00:00
if (!token || token !== process.env.MEDICATION_API_KEY) {
2026-01-18 05:28:35 +00:00
console.log('into the token not ok');
2026-01-18 04:56:42 +00:00
return res.status(401).json({ error: 'Unauthorized - Invalid API Key' });
}
2026-01-18 05:28:35 +00:00
console.log('off to next');
2026-01-18 04:56:42 +00:00
next();
};
export const validateShiftSyncApiKey = (req, res, next) => {
const authHeader = req.headers['authorization'];
const token = authHeader && authHeader.split(' ')[1];
if (!token || token !== process.env.SHIFTSYNC_API_KEY) {
return res.status(401).json({ error: 'Unauthorized - Invalid API Key' });
}
next();
};