WhatsApp-Logger-Self-Hosted-

A privacy-focused, self-hosted...
Log | Files | Refs | Activity | README | LICENSE

root / src / routes / auth.js

auth.js (1223B)


      1 const express = require('express');
      2 const { AUTH_USER, AUTH_PASS } = require('../config');
      3 const { SESSION_SECRET } = require('../auth');
      4 const { loginPage, loginFailedPage } = require('../views/pages');
      5 
      6 const router = express.Router();
      7 
      8 router.get('/login', (req, res) => {
      9     res.send(loginPage());
     10 });
     11 
     12 router.post('/login', (req, res) => {
     13     const { username, password, remember } = req.body;
     14 
     15     if (username === AUTH_USER && password === AUTH_PASS) {
     16         let cookieSettings = 'HttpOnly; Path=/;';
     17         if (remember === 'yes') cookieSettings += ' Max-Age=300;';
     18 
     19         res.setHeader('Set-Cookie', `auth_session=${SESSION_SECRET}; ${cookieSettings}`);
     20         return res.redirect('/');
     21     }
     22     res.status(401).send(loginFailedPage());
     23 });
     24 
     25 router.get('/logout', (req, res) => {
     26     res.setHeader('Set-Cookie', 'auth_session=; Max-Age=0; Path=/;');
     27     res.redirect('/login');
     28 });
     29 
     30 router.post('/api/verify', (req, res) => {
     31     const { username, password } = req.body;
     32 
     33     if (username === AUTH_USER && password === AUTH_PASS) {
     34         return res.json({ success: true, token: SESSION_SECRET });
     35     } else {
     36         return res.status(401).json({ success: false });
     37     }
     38 });
     39 
     40 module.exports = router;
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror