aboutsummaryrefslogtreecommitdiffstats
path: root/backend/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'backend/index.js')
-rw-r--r--backend/index.js11
1 files changed, 9 insertions, 2 deletions
diff --git a/backend/index.js b/backend/index.js
index 9dae733..090296e 100644
--- a/backend/index.js
+++ b/backend/index.js
@@ -7,6 +7,8 @@ const jwt = require('jsonwebtoken');
const app = express();
const PORT = 5000;
+const SECRET_KEY = 'your_jwt_secret'; // Replace with your actual secret key
+
// Middleware
app.use(bodyParser.json());
app.use(cors());
@@ -16,25 +18,30 @@ const users = [
{
id: 1,
username: 'admin',
- password: '$2a$10$QWJkLkFgD1kz6X.0Q1jDg.2aH3eRJ/Qnl72sDgB5DlQvPvFjsKFDi', // hashed password for 'password123'
+ password: '$2a$10$0chEQ/BjpmW2W9J1aA/BNOwF0aeFSBg4IAXnPjjLzSnQmXagdIzra', // hashed password for 'password123'
},
];
// Login route
app.post('/login', async (req, res) => {
const { username, password } = req.body;
+ console.log('Login attempt:', username, password);
const user = users.find((user) => user.username === username);
if (!user) {
+ console.log('User not found');
return res.status(401).json({ message: 'Invalid credentials' });
}
const isPasswordValid = await bcrypt.compare(password, user.password);
+ console.log('Password valid:', isPasswordValid);
if (!isPasswordValid) {
+ console.log('Invalid password');
return res.status(401).json({ message: 'Invalid credentials' });
}
- const token = jwt.sign({ id: user.id }, 'your_jwt_secret', { expiresIn: '1h' });
+ const token = jwt.sign({ id: user.id }, SECRET_KEY, { expiresIn: '1h' });
+ console.log('Token generated:', token);
res.json({ token });
});