File size: 778 Bytes
158961a 10c367b 158961a 10c367b 158961a 10c367b 158961a 10c367b 158961a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
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; |