From 23cb635b75fd047fd084a480e7499eb390e6285a Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Tue, 14 Nov 2023 23:50:24 +0000 Subject: [PATCH] simplify auth/password logic --- src/routes/auth.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/routes/auth.js b/src/routes/auth.js index 4fb2d05..530a312 100644 --- a/src/routes/auth.js +++ b/src/routes/auth.js @@ -67,18 +67,18 @@ router.post("/password", async (req, res) => { password: req.body.password, userid: req.cookies.username }; - const useridparsed = params.userid.split("@"); - const realmName = useridparsed[useridparsed.length - 1]; - const domains = (await requestPVE(`/access/domains`, "GET", pveAPIToken)).data.data; - const realm = domains.find((e) => e.realm === realmName); - const type = realm.type; - const types = db.getStatic().types.auth; + + const userRealm = params.userid.split("@").at(-1); + const domains = (await requestPVE("/access/domains", "GET", pveAPIToken)).data.data; + const realm = domains.find((e) => e.realm === userRealm); + const authTypes = db.getStatic().types.auth; + const realmType = authTypes[realm.type]; - if (types[type] === "pve") { - const response = await requestPVE("/access/password", "PUT", {cookies: req.cookies}, JSON.stringify(params)); - res.status(response.status).send(response.data) + if (realmType === "pve") { + const response = await requestPVE("/access/password", "PUT", { cookies: req.cookies }, JSON.stringify(params)); + res.status(response.status).send(response.data); } else { - res.status(501).send({error: `Auth type ${type} not implemented yet.`}) + res.status(501).send({ error: `Auth type ${realmType} not implemented yet.` }); } });