Build a secure user authentication system with registration, login, password reset, and JWT tokens
Implement a complete authentication system with user registration, login, password hashing, JWT token generation, and password reset functionality.
const jwt = require('jsonwebtoken');
const bcrypt = require('bcrypt');
async function registerUser(email, password) {
const hashedPassword = await bcrypt.hash(password, 10);
const user = await db.users.create({ email, password: hashedPassword });
return user;
}
function generateToken(userId) {
return jwt.sign({ userId }, process.env.JWT_SECRET, { expiresIn: '24h' });
}