| const express = require('express'); | |
| const jwt = require('jsonwebtoken'); | |
| const router = express.Router(); | |
| const JWT_SECRET = process.env.JWT_SECRET || 'your-secret-key'; | |
| const users = [ | |
| { | |
| id: 1, | |
| username: process.env.ADMIN_USERNAME, | |
| password: process.env.ADMIN_PASSWORD | |
| } | |
| ]; | |
| router.post('/login', (req, res) => { | |
| const { username, password } = req.body; | |
| const user = users.find(u => u.username === username && u.password === password); | |
| if (user) { | |
| const token = jwt.sign({ id: user.id, username: user.username }, JWT_SECRET, { expiresIn: '1h' }); | |
| res.json({ token }); | |
| } else { | |
| res.status(401).json({ error: 'ζ ζηη¨ζ·εζε―η ' }); | |
| } | |
| }); | |
| module.exports = router; |