Files
hDiyanetProxy/backend/src/middleware/auth.js
hOLOlu a798066049 İlk sürüm: hDiyanetProxy v1.0.0
- Backend: Node.js + Express + MySQL + JWT auth
- 8 MySQL tablosu (users, countries, states, cities, prayer_times, ramadan_times, eid_times, fetch_logs)
- Diyanet API entegrasyonu (auth + token yönetimi)
- Tüm API endpointleri (places, prayer-times, ramadan, eid, admin)
- Rate limiting, CORS, input validation
- Cron job (gece 02:00 otomatik veri çekme)
- Frontend: Login, Dashboard, Fetch Panel, Namaz Vakitleri, Ramazan, Admin, Profil
- Admin kullanıcı: admin/admin123
2026-02-27 07:53:41 +03:00

32 lines
876 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// hDiyanetProxy - JWT Auth Middleware
const jwt = require('jsonwebtoken');
// Token doğrulama middleware'i
function authMiddleware(req, res, next) {
const authHeader = req.headers.authorization;
if (!authHeader || !authHeader.startsWith('Bearer ')) {
return res.status(401).json({ error: 'Yetkilendirme token\'ı gerekli' });
}
const token = authHeader.split(' ')[1];
try {
const decoded = jwt.verify(token, process.env.JWT_SECRET);
req.user = decoded;
next();
} catch (err) {
return res.status(401).json({ error: 'Geçersiz veya süresi dolmuş token' });
}
}
// Admin rolü kontrolü middleware'i
function adminMiddleware(req, res, next) {
if (req.user.role !== 'admin') {
return res.status(403).json({ error: 'Bu işlem için admin yetkisi gerekli' });
}
next();
}
module.exports = { authMiddleware, adminMiddleware };