Optional password protection for the web server

This commit is contained in:
Cadence Ember
2025-02-25 14:36:49 +13:00
parent 3bc37857bb
commit 3b034dd6e5
9 changed files with 103 additions and 32 deletions
+9 -7
View File
@@ -37,13 +37,15 @@ as.router.get("/oauth", defineEventHandler(async event => {
const session = await auth.useSession(event)
let scope = "guilds"
const parsedFirstQuery = await getValidatedQuery(event, schema.first.safeParse)
if (parsedFirstQuery.data?.action === "add") {
scope = "bot+guilds"
await session.update({selfService: false})
} else if (parsedFirstQuery.data?.action === "add-self-service") {
scope = "bot+guilds"
await session.update({selfService: true})
if (!reg.ooye.web_password || reg.ooye.web_password === session.data.password) {
const parsedFirstQuery = await getValidatedQuery(event, schema.first.safeParse)
if (parsedFirstQuery.data?.action === "add") {
scope = "bot+guilds"
await session.update({selfService: false})
} else if (parsedFirstQuery.data?.action === "add-self-service") {
scope = "bot+guilds"
await session.update({selfService: true})
}
}
async function tryAgain() {
+21
View File
@@ -0,0 +1,21 @@
// @ts-check
const {z} = require("zod")
const {defineEventHandler, readValidatedBody, sendRedirect} = require("h3")
const {as, sync} = require("../../passthrough")
/** @type {import("../auth")} */
const auth = sync.require("../auth")
const schema = {
password: z.object({
password: z.string()
})
}
as.router.post("/api/password", defineEventHandler(async event => {
const {password} = await readValidatedBody(event, schema.password.parse)
const session = await auth.useSession(event)
await session.update({password})
return sendRedirect(event, "../")
}))