-
Notifications
You must be signed in to change notification settings - Fork 0
/
authenticate.js
30 lines (26 loc) · 1.02 KB
/
authenticate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const fs = require("fs");
const { fetchUserInfo } = require("./fetchUserInfo");
//SUPER NAIVE DEMO OF SIGNING IN WITH RAVENCOIN NFTS
//With as few lines of code as possible.
async function authenticate(req, res) {
const orderRef = req.query.orderRef;
const data = await fetchUserInfo(orderRef);
//Write the result to file and set a cookie
const random = "" + Math.random() * 10000000;
if (data) {
const folder = "./sessions";
fs.mkdirSync(folder, { recursive: true });
fs.writeFileSync(folder + "/" + random + ".json", JSON.stringify(data));
res.cookie("sessionCookie", random, {
expires: new Date(Date.now() + 1900000),
});
//Seems like we cant redirect, so we do it with location/javascript
res.send(`<html><body>
<script>
setTimeout( () => {window.location.href="/secure";},1000);</script>
</body></html>`);
return;
}
res.status(500).send({ error: "Something went wrong" });
}
exports.authenticate = authenticate;