mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-11-09 00:10:10 +01:00
6b6007f9ad
* Enable the system owner to be able to update the system wide password and secret * lint and cleanup
35 lines
787 B
JavaScript
35 lines
787 B
JavaScript
process.env.NODE_ENV === "development"
|
|
? require("dotenv").config({ path: `.env.${process.env.NODE_ENV}` })
|
|
: require("dotenv").config();
|
|
const JWT = require("jsonwebtoken");
|
|
|
|
function reqBody(request) {
|
|
return typeof request.body === "string"
|
|
? JSON.parse(request.body)
|
|
: request.body;
|
|
}
|
|
|
|
function queryParams(request) {
|
|
return request.query;
|
|
}
|
|
|
|
function makeJWT(info = {}, expiry = "30d") {
|
|
if (!process.env.JWT_SECRET)
|
|
throw new Error("Cannot create JWT as JWT_SECRET is unset.");
|
|
return JWT.sign(info, process.env.JWT_SECRET, { expiresIn: expiry });
|
|
}
|
|
|
|
function decodeJWT(jwtToken) {
|
|
try {
|
|
return JWT.verify(jwtToken, process.env.JWT_SECRET);
|
|
} catch {}
|
|
return { p: null };
|
|
}
|
|
|
|
module.exports = {
|
|
reqBody,
|
|
queryParams,
|
|
makeJWT,
|
|
decodeJWT,
|
|
};
|