Files
ws-api-node/components/auth.js
aurik3 0eeb2a22d5 asdasd
asdasdad
2022-09-15 13:39:04 -05:00

61 lines
1.8 KiB
JavaScript

const router = require("express").Router();
const fs = require("fs");
router.get("/checkauth", async (req, res) => {
client
.getState()
.then((data) => {
console.log(data);
res.send(data);
})
.catch((err) => {
if (err) {
res.send("DISCONNECTED");
}
});
});
router.get("/getqr", async (req, res) => {
client
.getState()
.then((data) => {
if (data) {
res.write("<html><body><h2>Already Authenticated</h2></body></html>");
res.end();
} else sendQr(res);
})
.catch(() => sendQr(res));
});
function sendQr(res) {
fs.readFile("components/last.qr", (err, last_qr) => {
if (!err && last_qr) {
var page = `
<html>
<body>
<script type="module">
</script>
<div id="qrcode"></div>
<script type="module">
import QrCreator from "https://cdn.jsdelivr.net/npm/qr-creator/dist/qr-creator.es6.min.js";
let container = document.getElementById("qrcode");
QrCreator.render({
text: "${last_qr}",
radius: 0.5, // 0.0 to 0.5
ecLevel: "H", // L, M, Q, H
fill: "#536DFE", // foreground color
background: null, // color or null for transparent
size: 256, // in pixels
}, container);
</script>
</body>
</html>
`;
res.write(page);
res.end();
}
});
}
module.exports = router;