mirror of
https://github.com/apotdevin/thunderhub.git
synced 2025-02-21 14:04:03 +01:00
chore: 🔧 conditional refresh cookie and logging
This commit is contained in:
parent
f91f177b9d
commit
43fedeab6e
2 changed files with 4 additions and 3 deletions
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue