Created the token controller

This commit is contained in:
2022-12-27 15:04:16 +01:00
parent 04fd71b7b7
commit a6e6261b14

View File

@ -0,0 +1,22 @@
const fs = require('fs');
const crypto = require('crypto');
const JWT_PATH = process.cwd()+"/data/.jwt";
let jwtToken;
module.exports.createToken = () => {
if (fs.existsSync(JWT_PATH)) {
jwtToken = fs.readFileSync(JWT_PATH, 'utf8');
return;
}
// Generate new token
jwtToken = crypto.randomBytes(50).toString('hex');
fs.writeFile(JWT_PATH, jwtToken, () => {});
}
module.exports.getToken = () => {
if (!jwtToken) this.createToken();
return jwtToken;
}