const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const userAuthentication = require('./middlewares/userAuthentication');
const { signup } = require('./app');
const { login } = require('./login');
const PORT = 3003;
const app = express();

app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static(path.join(__dirname, 'public')));

app.post('/login', login);

app.get('/dashboard', userAuthentication, (req, res) => {
    res.send('<h1>Welcome to the dashboard</h1> <a href="/logout">Logout</a>');
});

app.get('/logout', (req, res) => {
    res.redirect('/login')
});

app.post('/signup', signup);

app.listen(PORT, () => {
    console.log(`Server is running on ${PORT}`);
})

