text: const express = require('express');
  const router = express.Router();
  const mysqlDB = require('../../mysql');
  const checkAuth = require('../auth/auth');
  const jwt = require('jsonwebtoken');
  
  router.get('/', (req, res, next) => {
      res.status(200).json({
          message: 'Handling GET requests to /users'
      })
  });
  
  router.post('/', (req, res, next) => {
      const db = mysqlDB.connect();
  
      db.query("select * from users where username = ?", [req.body.username],
          (err, result) => {
              if (err) throw err;
              else if (result.length > 0 && result[0].username == req.body.username && result[0].password == req.body.password) {
                  const token = jwt.sign({
                      userId: result[0].userId,
                      username: result[0].username,
                      role: result[0].role
                  },
                      process.env.JWT_KEY,
                      {
                          expiresIn: "1h"
                      });
                  req.session.role = result[0].role;
                  res.status(200).json({
                      message: 'Signed in',
                      token: token
                  })
              }
              else {
                  res.status(400).json({
                      error: 'Auth failed'
                  })
              }
          })
  
      mysqlDB.close(db);
  });
  
  router.get('/logout', checkAuth, (req, res, next) => {
      console.log("mohr")
      req.session.destroy();
      res.redirect('http://localhost:3000');
  })
  
  router.post('/create', checkAuth, (req, res, next) => {
      const db = mysqlDB.connect();
      console.log(req.body.category);
  
      db.query("insert into users (username, password, role, groupID, categoryID, points) values (?, ?, ?, ?, ?, ?)", [req.body.username, req.body.password, "user", req.body.group, req.body.category, 0],
          (err, result) => {
              if (err) {
                  res.status(400).send();
              } else {
                  res.status(200).send();
              }
          });
      mysqlDB.close(db);
  });
  
  router.get('/:userId', (req, res, next) => {
      const id = req.params.userId;
      if (id == 'special') {
          res.status(200).json({
              message: 'Special ID',
              id: id
          });
      } else {
          res.status(200).json({
              message: 'Passed ID',
              id: id
          });
      }
  });
  
  module.exports = router;