chore: 🔧 conditional refresh cookie and logging

This commit is contained in:
AP 2020-05-20 06:26:29 +02:00
parent f91f177b9d
commit 43fedeab6e
2 changed files with 4 additions and 3 deletions

View file

@ -191,7 +191,6 @@ export const createDirectory = (dirname: string) => {
const curDir = path.resolve(parentDir, childDir);
try {
if (!fs.existsSync(curDir)) {
logger.verbose(`Creating cookie directory at: ${curDir}`);
fs.mkdirSync(curDir);
}
} catch (err) {
@ -220,6 +219,7 @@ export const readCookie = (cookieFile: string): string | null => {
const exists = fs.existsSync(cookieFile);
if (exists) {
try {
logger.info(`Found cookie at path ${cookieFile}`);
const cookie = fs.readFileSync(cookieFile, 'utf-8');
return cookie;
} catch (err) {
@ -232,6 +232,8 @@ export const readCookie = (cookieFile: string): string | null => {
createDirectory(dirname);
fs.writeFileSync(cookieFile, crypto.randomBytes(64).toString('hex'));
logger.info(`Cookie created at directory: ${dirname}`);
const cookie = fs.readFileSync(cookieFile, 'utf-8');
return cookie;
} catch (err) {

View file

@ -30,9 +30,8 @@ export const getAuthToken = {
const cookieFile = readCookie(cookiePath);
refreshCookie(cookiePath);
if (cookieFile === params.cookie) {
refreshCookie(cookiePath);
const token = jwt.sign({ user: SSO_ACCOUNT }, secret);
return token;
}