diff --git a/server/controller/token.js b/server/controller/token.js new file mode 100644 index 0000000..f20eb7c --- /dev/null +++ b/server/controller/token.js @@ -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; +} \ No newline at end of file