CoastalCommitsPastes/client/pages/api/auth/requires-passcode.ts

35 lines
818 B
TypeScript
Raw Normal View History

2022-11-09 21:38:05 -05:00
import config from "@lib/config"
import { NextApiRequest, NextApiResponse } from "next"
export const getRequiresPasscode = async () => {
const requiresPasscode = Boolean(config.registration_password)
return requiresPasscode
}
const handleRequiresPasscode = async (
2022-11-10 02:11:36 -05:00
_: NextApiRequest,
2022-11-09 21:38:05 -05:00
res: NextApiResponse
) => {
return res.json({ requiresPasscode: await getRequiresPasscode() })
}
export default async function requiresPasscode(
req: NextApiRequest,
res: NextApiResponse
) {
const { slug } = req.query
if (!slug || Array.isArray(slug)) {
return res.status(400).json({ error: "Missing param" })
}
switch (req.method) {
case "GET":
if (slug === "requires-passcode") {
return handleRequiresPasscode(req, res)
}
default:
return res.status(405).json({ error: "Method not allowed" })
}
}