From f517b6838b48121cfb3308ea9d03c6a9f888a95d Mon Sep 17 00:00:00 2001 From: Cohen Erickson Date: Tue, 14 Feb 2023 00:58:04 +0000 Subject: [PATCH 1/3] Fix service worker registration --- public/sw.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/public/sw.js b/public/sw.js index e2c1c7b..c1b8c40 100644 --- a/public/sw.js +++ b/public/sw.js @@ -1,3 +1,5 @@ +importScripts("./uv/uv.bundle.js"); +importScripts("./uv/uv.config.js"); importScripts("./uv/uv.sw.js"); importScripts("./osana/osana.worker.js"); From 6f8cf69e8cc32fb001984cae80807111b42eb5d0 Mon Sep 17 00:00:00 2001 From: Cohen Erickson Date: Tue, 14 Feb 2023 00:58:36 +0000 Subject: [PATCH 2/3] Fix `/` <--> `/login` loop --- app.js | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/app.js b/app.js index dc94fd8..24d1fb6 100644 --- a/app.js +++ b/app.js @@ -43,9 +43,9 @@ app.use( // Verification app.patch("/generate-otp", async (req, res) => { if ( - config.sendgrid_verification == true || - config.discord_verification == true || - config.smtp_verificaton == true + config.sendgrid_verification || + config.discord_verification || + config.smtp_verificaton ) { const OTP = generateCode(); ACTIVE_CODES.add(OTP); @@ -64,7 +64,7 @@ app.patch("/generate-otp", async (req, res) => { (this message is automated)` }; - if (config.sendgrid_verification == true) { + if (config.sendgrid_verification) { sgMail.setApiKey(config.sendgrid_options.api_key); email.to = config.sendgrid_options.to_email; @@ -76,7 +76,7 @@ app.patch("/generate-otp", async (req, res) => { } } - if (config.smtp_verification == true) { + if (config.smtp_verification) { const smtpMailerAgent = nodemailer.createTransport(config.smtp_options); email.to = config.smtp_options.to_email; @@ -88,7 +88,7 @@ app.patch("/generate-otp", async (req, res) => { } } - if (config.discord_verification == true) { + if (config.discord_verification) { try { await fetch(config.webhook_url, { method: "POST", @@ -117,9 +117,9 @@ function generateCode() { app.post("/validate-otp", (req, res) => { if ( - config.sendgrid_verification == true || - config.discord_verification == true || - config.smtp_verificaton == true + config.sendgrid_verification || + config.discord_verification || + config.smtp_verificaton ) { const OTP = req.body.otp; @@ -163,9 +163,9 @@ app.use(express.static(path.join(__dirname, "public"))); // Login route app.get("/login", (req, res) => { if ( - config.sendgrid_verification == true || - config.discord_verification == true || - config.smtp_verificaton == true + config.sendgrid_verification || + config.discord_verification || + config.smtp_verificaton ) { res.sendFile(path.join(__dirname, "src", "unv.html")); } else { @@ -175,12 +175,17 @@ app.get("/login", (req, res) => { // General Routes app.use((req, res, next) => { - const verification = req.cookies["validation"]; - if (!verification || !validateToken(verification)) { - res.redirect("/login"); - } else { - next(); + if ( + config.sendgrid_verification || + config.discord_verification || + config.smtp_verificaton + ) { + const verification = req.cookies["validation"]; + if (!verification || !validateToken(verification)) { + return res.redirect("/login"); + } } + next(); }); app.get("/", (req, res) => { @@ -226,7 +231,6 @@ function hash(token) { } function validateToken(verification) { - console.log(verification); const [id, token] = verification.split(":"); const tokenData = TOKENS.find((token) => token.id == id); From 8603734c7a9bf95fc28210712158593f09e212e6 Mon Sep 17 00:00:00 2001 From: Cohen Erickson Date: Tue, 14 Feb 2023 01:04:34 +0000 Subject: [PATCH 3/3] Fix missing memory.txt issue --- app.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app.js b/app.js index 24d1fb6..0e27b6c 100644 --- a/app.js +++ b/app.js @@ -14,6 +14,9 @@ import bcrypt from "bcrypt"; const PORT = process.env.PORT || 3000; const __dirname = process.cwd(); const ACTIVE_CODES = new Set(); +if (!fs.existsSync("./memory.txt")) { + fs.writeFileSync("./memory.txt", "", "utf-8"); +} let TOKENS = fs .readFileSync("./memory.txt", "utf-8") .trim()