İ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
This commit is contained in:
31
backend/src/middleware/auth.js
Normal file
31
backend/src/middleware/auth.js
Normal file
@@ -0,0 +1,31 @@
|
||||
// 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 };
|
||||
Reference in New Issue
Block a user