Browse Source

fixup: lint errors

pull/914/head
Philip H. 1 year ago
committed by GitHub
parent
commit
b7c2c81cc7
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 65
      src/lib/Server.js

65
src/lib/Server.js

@ -21,6 +21,7 @@ const {
setHeader, setHeader,
serveStatic, serveStatic,
} = require('h3'); } = require('h3');
const Util = require('./Util');
const WireGuard = require('../services/WireGuard'); const WireGuard = require('../services/WireGuard');
@ -67,42 +68,42 @@ module.exports = class Server {
return UI_TRAFFIC_STATS === 'true'; return UI_TRAFFIC_STATS === 'true';
})) }))
// Authentication // Authentication
.get('/api/session', defineEventHandler((event) => { .get('/api/session', defineEventHandler((event) => {
const requiresPassword = !!process.env.PASSWORD; const requiresPassword = !!process.env.PASSWORD;
const authenticated = requiresPassword const authenticated = requiresPassword
? !!(event.node.req.session && event.node.req.session.authenticated) ? !!(event.node.req.session && event.node.req.session.authenticated)
: true; : true;
return { return {
requiresPassword, requiresPassword,
authenticated, authenticated,
}; };
})) }))
.post('/api/session', defineEventHandler(async (event) => { .post('/api/session', defineEventHandler(async (event) => {
const { password } = await readBody(event); const { password } = await readBody(event);
if (typeof password !== 'string') { if (typeof password !== 'string') {
throw createError({ throw createError({
status: 401, status: 401,
message: 'Missing: Password', message: 'Missing: Password',
}); });
} }
if (password !== PASSWORD) { if (password !== PASSWORD) {
throw createError({ throw createError({
status: 401, status: 401,
message: 'Incorrect Password', message: 'Incorrect Password',
}); });
} }
event.node.req.session.authenticated = true; event.node.req.session.authenticated = true;
event.node.req.session.save(); event.node.req.session.save();
debug(`New Session: ${event.node.req.session.id}`); debug(`New Session: ${event.node.req.session.id}`);
return { succcess: true }; return { succcess: true };
}))); })));
// WireGuard // WireGuard
app.use( app.use(

Loading…
Cancel
Save