const express = require('express');

const router = express.Router();

router.get('/key', async(req, res) => {
    var key = req.query.s;
    var session = req.session;
    if(!session.passport){
      return res.status(400).send('Session telah habis, harap login lagi!');
    }
    if (session.passport.user[key]){
      return res.send(session.passport.user[key]);
    }
    return res.status(400).send('Gagal menarik data, harap login lagi!');
});

router.get('/set', async(req, res) => {
  var key = req.query.s;
  var val = req.query.v;
  var session = req.session;
  if(key && val){
    session[key] = val;
  }
  return res.redirect('/');
});

module.exports = router;