Skip to content

Commit

Permalink
handle HEAD /session to check for logged-in state [server deploy]
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianoFerrari committed Jan 12, 2024
1 parent ca5d528 commit 5a9d0d9
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/index.ts
Expand Up @@ -494,6 +494,24 @@ wss.on('error', (err) => {
console.error(err);
});


app.head('/session', (req, res) => {
if (req.session) {
if (req.session.user) {
res.status(200).send();
} else {
// Session found without user field
console.error('Session user not found:', req.session)
req.session.destroy((err) => {
if(err) { console.log(err); }
res.status(401).send();
});
}
} else {
res.status(401).send();
}
});

server.on('upgrade', async (request, socket, head) => {
sessionParser(request, {}, (err) => {
if (err) {
Expand Down Expand Up @@ -843,6 +861,8 @@ app.post('/hooks', async (req, res) => {
});




/* ==== Mail confirmation ==== */

let confirmedHandler = (email) => {
Expand All @@ -867,6 +887,9 @@ app.post('/mlhooks', async (req, res) => {
res.json({received: true});
});




/* ==== Export ==== */

app.post('/export-docx', async (req, res) => {
Expand Down Expand Up @@ -932,6 +955,10 @@ app.post('/test/confirm', async (req, res) => {
});




/* ==== Utils ==== */

app.get('/utils/compact', (req, res) => {
if (req.hostname === 'localhost' || req.hostname === '127.0.0.1') {
const daysAgo = req.query.daysAgo;
Expand Down

0 comments on commit 5a9d0d9

Please sign in to comment.