fix error + format
This commit is contained in:
+23
-24
@@ -1,7 +1,7 @@
|
||||
import * as signature from "cookie-signature";
|
||||
import fs from "fs";
|
||||
import getIP from "./getip.js";
|
||||
const cookiesecret = fs.readFileSync("cookiesecret.txt").toString();
|
||||
import * as signature from 'cookie-signature'
|
||||
import fs from 'fs'
|
||||
import getIP from './getip.js'
|
||||
const cookiesecret = fs.readFileSync('cookiesecret.txt').toString()
|
||||
/**
|
||||
* usignes a string
|
||||
* @param {string} text text to unsign
|
||||
@@ -10,14 +10,14 @@ const cookiesecret = fs.readFileSync("cookiesecret.txt").toString();
|
||||
* @return {string/boolean} unsigned text, or if unsigning was unsuccessful, false
|
||||
*/
|
||||
function unsign(text, req, res) {
|
||||
let ip = getIP(req);
|
||||
let unsigned = signature.unsign(text, cookiesecret + ip);
|
||||
let ip = getIP(req)
|
||||
let unsigned = signature.unsign(text, cookiesecret + ip)
|
||||
if (!unsigned) {
|
||||
unsigned = signature.unsign(text, cookiesecret); //unsafe login?
|
||||
if(!unsigned)return false;
|
||||
unsigned = signature.unsign(text, cookiesecret) //unsafe login?
|
||||
if (!unsigned) return false
|
||||
return unsigned
|
||||
}
|
||||
return unsigned;
|
||||
return unsigned
|
||||
}
|
||||
/**
|
||||
* unsignes the auth cookie of a request, also sends json response if auth cookie was invalid
|
||||
@@ -26,26 +26,25 @@ function unsign(text, req, res) {
|
||||
* @return {string/boolean} unsigned cookie, or if unsigning was unsuccessful, false
|
||||
*/
|
||||
function getunsigned(req, res) {
|
||||
let cookie = req.cookies.AUTH_COOKIE;
|
||||
let cookie = req.cookies.AUTH_COOKIE
|
||||
if (!cookie) {
|
||||
res.status(403);
|
||||
res.json({ "error": "you are not logged in! (no cookie)" });
|
||||
return;
|
||||
res.status(403)
|
||||
res.json({ error: 'you are not logged in! (no cookie)' })
|
||||
return
|
||||
}
|
||||
let unsigned = unsign(cookie, req, res);
|
||||
let unsigned = unsign(cookie, req, res)
|
||||
if (!unsigned) {
|
||||
try {
|
||||
res.status(401);
|
||||
res.json({ "error": "Bad auth cookie set" });
|
||||
}
|
||||
catch (ignored) { } //sometimes it errors, gotta debug soon
|
||||
return false;
|
||||
res.status(401)
|
||||
res.json({ error: 'Bad auth cookie set' })
|
||||
} catch (ignored) {} //sometimes it errors, gotta debug soon
|
||||
return false
|
||||
}
|
||||
return decodeURIComponent(unsigned);
|
||||
return decodeURIComponent(unsigned)
|
||||
}
|
||||
export { unsign };
|
||||
export { getunsigned };
|
||||
export { unsign }
|
||||
export { getunsigned }
|
||||
export default {
|
||||
unsign: unsign,
|
||||
getunsigned: getunsigned
|
||||
};
|
||||
getunsigned: getunsigned,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user