forked from seetransparent/addax
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthentication.js
More file actions
27 lines (24 loc) · 762 Bytes
/
authentication.js
File metadata and controls
27 lines (24 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const fs = require('fs');
const path = require('path');
function readAuthFile() {
const authFile = path.join('.', 'auth.json');
return new Promise((resolve, reject) => {
fs.access(authFile, fs.constants.R_OK, (err) => {
// if the file does not exist, read it as an empty object
if (err) return resolve({});
fs.readFile(authFile, (err, file) => {
if (err) return reject(err);
resolve(JSON.parse(file));
});
});
});
}
function writeAuthFile(jsonData) {
return new Promise((resolve, reject) => {
fs.writeFile(path.join('.', 'auth.json'), JSON.stringify(jsonData, null, 2), (err) => {
if (err) return reject(err);
resolve();
});
});
}
module.exports = { readAuthFile, writeAuthFile };