Skip to content

Commit

Permalink
updates for failed cookie auth, and to restart so node library works …
Browse files Browse the repository at this point in the history
…correctly next time (#36)
  • Loading branch information
imnotbob committed Dec 28, 2020
1 parent 1ce50dc commit 23cfdf6
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions index.js
Expand Up @@ -210,14 +210,33 @@ function startWebConfig() {
formerRegistrationData: runTimeData.savedConfig.cookieData
}, (err, result) => {
if (result && Object.keys(result).length >= 2) {
sendCookiesToEndpoint((configData.settings.appCallbackUrl ? String(configData.settings.appCallbackUrl).replace("/receiveData?", "/cookie?") : null), result);
runTimeData.savedConfig.cookieData = result;
// console.log('RESULT: ' + err + ' / ' + JSON.stringify(result));
logger.info('Successfully Refreshed Alexa Cookie...');
res.send({
result: JSON.stringify(result)
isCookieValid(result)
.then((valid) => {
if (valid) {
sendCookiesToEndpoint((configData.settings.appCallbackUrl ? String(configData.settings.appCallbackUrl).replace("/receiveData?", "/cookie?") : null), result);
runTimeData.savedConfig.cookieData = result;
// console.log('RESULT: ' + err + ' / ' + JSON.stringify(result));
logger.info('Successfully Refreshed Alexa Cookie...');
res.send({
result: JSON.stringify(result)
});
} else {
logger.error(`** ERROR: Unsuccessfully refreshed Alexa Cookie it was found to be invalid/expired... **`);
logger.error('RESULT: ' + err + ' / ' + JSON.stringify(result));
logger.warn(`** WARNING: We are clearing the Cookie from ${configData.settings.hubPlatform} to prevent further requests and server load... **`);
sendClearAuthToST()
}
});
} else {
logger.error(`** ERROR: Unsuccessfully refreshed Alexa Cookie it was found to be invalid/expired... **`);
logger.error('RESULT: ' + err + ' / ' + JSON.stringify(result));
logger.warn(`** WARNING: We are clearing the Cookie from ${configData.settings.hubPlatform} to prevent further requests and server load... **`);
sendClearAuthToST()
}
setTimeout(() => {
logger.warn("Restarting after cookie refresh attempt");
process.exit(1);
}, 25 * 1000);
});
});
webApp.get('/configData', (req, res) => {
Expand Down Expand Up @@ -854,4 +873,4 @@ function exitHandler(options, exitCode) {
console.error("Could not close connections in time, forcefully shutting down");
process.exit(1);
}, 2 * 1000);
}
}

0 comments on commit 23cfdf6

Please sign in to comment.