1
0
goodtimes/server/routes/groups.js
James Ketrenos 4c6040e3bc Auth is working again with express-session for user tracking
Signed-off-by: James Ketrenos <james_eikona@ketrenos.com>
2022-04-07 16:36:56 -07:00

44 lines
978 B
JavaScript
Executable File

const express = require('express'),
router = express.Router(),
crypto = require('crypto');
router.get('/', async (req, res/*, next*/) => {
console.log('GET /groups/', req.session.userId);
return res.status(200).send(
[ {
id: 1,
ownerId: 1,
name: 'Beer Tuesday',
nextEvent: Date.now() + 86400 * 14 * 1000 /* 2 weeks from now */
} ]
);
});
router.post('/:id', async (req, res) => {
const { id } = req.params;
let userId;
if (!req.cookies.user) {
userId = crypto.randomBytes(16).toString('hex');
res.cookie('user', userId);
} else {
userId = req.cookies.user;
}
const group = {
id: 1
};
if (id) {
console.log(`[${userId.substring(0,8)}]: Attempting load of ${id}`);
} else {
console.log(`[${userId.substring(0,8)}]: Creating new group.`);
}
console.log(`[${userId.substring(0,8)}]: ${group.id} loaded.`);
return res.status(200).send({ id: group.id });
});
module.exports = router;