Skip to content

Instantly share code, notes, and snippets.

@mcsee
Created October 18, 2025 13:54
Show Gist options
  • Save mcsee/ba50d84d91ab9e26cd0a7d84a5fec633 to your computer and use it in GitHub Desktop.
Save mcsee/ba50d84d91ab9e26cd0a7d84a5fec633 to your computer and use it in GitHub Desktop.
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
import bcrypt from 'bcrypt';
app.post('/login', async (req, res) => {
const { username, password } = req.body;
const user = await Users.findOne({ username });
if (!user) return res.status(401).send('Invalid credentials');
const valid = await bcrypt.compare(password, user.password);
if (!valid) return res.status(401).send('Invalid credentials');
res.send('Login successful');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment