structure ready
Deploy Node App / deploy (push) Successful in 25s

This commit is contained in:
Gitea
2026-06-15 15:43:09 +05:30
commit 41d82f9266
12 changed files with 6460 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
const postgre = require('../database/postgre');
const jwt = require('jsonwebtoken');
const JWT_SECRET = 'secretkey';
const loginUser = async (req, res) => {
try {
const { email, password } = req.body;
if (!email || !password) {
return res.status(400).json({
success: false,
message: 'Email and password are required'
});
}
const result = await postgre.query(
'SELECT * FROM users WHERE email = $1 AND password = $2',
[email, password]
);
if (result.rows.length === 0) {
return res.status(401).json({
success: false,
message: 'Invalid email or password'
});
}
const user = result.rows[0];
const token = jwt.sign(
{
id: user.id,
user: user.user
},
JWT_SECRET,
{ expiresIn: '24h' }
);
res.status(200).json({
success: true,
message: 'Login successful',
token
});
} catch (error) {
console.error(error);
res.status(500).json({
success: false,
message: error.message
});
}
};
module.exports = { loginUser };