mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-21 17:33:29 +01:00
Fix overeager token cleanup
This commit is contained in:
@@ -39,16 +39,22 @@ export class InMemorySmapiTokenStore implements SmapiTokenStore {
|
|||||||
const smapiToken = this.tokens[tokenKey];
|
const smapiToken = this.tokens[tokenKey];
|
||||||
if (smapiToken) {
|
if (smapiToken) {
|
||||||
const verifyResult = smapiAuthTokens.verify(smapiToken);
|
const verifyResult = smapiAuthTokens.verify(smapiToken);
|
||||||
// Delete if token verification fails (expired or invalid)
|
// Only delete if token verification fails with InvalidTokenError
|
||||||
|
// Do NOT delete ExpiredTokenError as those can still be refreshed
|
||||||
if (E.isLeft(verifyResult)) {
|
if (E.isLeft(verifyResult)) {
|
||||||
|
const error = verifyResult.left;
|
||||||
|
// Only delete invalid tokens, not expired ones (which can be refreshed)
|
||||||
|
if (error._tag === 'InvalidTokenError') {
|
||||||
|
logger.debug(`Deleting invalid token from in-memory store`);
|
||||||
delete this.tokens[tokenKey];
|
delete this.tokens[tokenKey];
|
||||||
deletedCount++;
|
deletedCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (deletedCount > 0) {
|
if (deletedCount > 0) {
|
||||||
logger.info(`Cleaned up ${deletedCount} expired token(s) from in-memory store`);
|
logger.info(`Cleaned up ${deletedCount} invalid token(s) from in-memory store`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return deletedCount;
|
return deletedCount;
|
||||||
@@ -134,16 +140,22 @@ export class FileSmapiTokenStore implements SmapiTokenStore {
|
|||||||
const smapiToken = this.tokens[tokenKey];
|
const smapiToken = this.tokens[tokenKey];
|
||||||
if (smapiToken) {
|
if (smapiToken) {
|
||||||
const verifyResult = smapiAuthTokens.verify(smapiToken);
|
const verifyResult = smapiAuthTokens.verify(smapiToken);
|
||||||
// Delete if token verification fails (expired or invalid)
|
// Only delete if token verification fails with InvalidTokenError
|
||||||
|
// Do NOT delete ExpiredTokenError as those can still be refreshed
|
||||||
if (E.isLeft(verifyResult)) {
|
if (E.isLeft(verifyResult)) {
|
||||||
|
const error = verifyResult.left;
|
||||||
|
// Only delete invalid tokens, not expired ones (which can be refreshed)
|
||||||
|
if (error._tag === 'InvalidTokenError') {
|
||||||
|
logger.debug(`Deleting invalid token from file store`);
|
||||||
delete this.tokens[tokenKey];
|
delete this.tokens[tokenKey];
|
||||||
deletedCount++;
|
deletedCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (deletedCount > 0) {
|
if (deletedCount > 0) {
|
||||||
logger.info(`Cleaned up ${deletedCount} expired token(s) from file store`);
|
logger.info(`Cleaned up ${deletedCount} invalid token(s) from file store`);
|
||||||
this.saveToFile();
|
this.saveToFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user