

const express = require('express'); const jwt = require('jsonwebtoken'); const bcrypt = require('bcrypt'); const User = require('./models/User'); // Your user model const app = express(); app.use(express.json()); // User registration app.post('/register', async (req, res) => { const { email, password } = req.body; const hashedPassword = await bcrypt.hash(password, 10); const user = new User({ email, password: hashedPassword }); await user.save(); const token = jwt.sign({ userId: user._id }, 'secretKey'); res.json({ token }); }); // User login app.post('/login', async (req, res) => { const { email, password } = req.body; const user = await User.findOne({ email }); if (user && await bcrypt.compare(password, user.password)) { const token = jwt.sign({ userId: user._id }, 'secretKey'); res.json({ token }); } else { res.status(400).json({ message: 'Invalid credentials' }); } }); // More routes for profile handling, messaging, etc. app.listen(3000, () => { console.log('Server running on port 3000'); });
const express = require('express'); const jwt = require('jsonwebtoken'); const bcrypt = require('bcrypt'); const User = require('./models/User'); // Your user model const app = express(); app.use(express.json()); // User registration app.post('/register', async (req, res) => { const { email, password } = req.body; const hashedPassword = await bcrypt.hash(password, 10); const user = new User({ email, password: hashedPassword }); await user.save(); const token = jwt.sign({ userId: user._id }, 'secretKey'); res.json({ token }); }); // User login app.post('/login', async (req, res) => { const { email, password } = req.body; const user = await User.findOne({ email }); if (user && await bcrypt.compare(password, user.password)) { const token = jwt.sign({ userId: user._id }, 'secretKey'); res.json({ token }); } else { res.status(400).json({ message: 'Invalid credentials' }); } }); // More routes for profile handling, messaging, etc. app.listen(3000, () => { console.log('Server running on port 3000'); });
