Autogenerate JWT secret if not in production mode

This commit is contained in:
D. Berge
2020-08-12 15:13:53 +02:00
parent 9453d14ee5
commit 6fa39eb3c7

View File

@@ -40,6 +40,16 @@ try {
if (text) {
config = JSON.parse(text);
}
if (process.env.NODE_ENV != "production") {
if (!config.jwt || !config.jwt.secret) {
const buffer = Buffer.alloc(64);
crypto.randomFillSync(buffer, 0, buffer.length);
config.jwt.secret = buffer.toString("base64");
console.warn("Autogenerated JWT secret (NODE_ENV != production)");
}
}
}
} catch (err) {
console.error(err);