Another token expiration fix.

This commit is contained in:
Wolfgang Kulhanek
2025-10-24 15:07:09 +02:00
parent 03434fb362
commit 2403d6cdc6

View File

@@ -250,11 +250,10 @@ class SonosSoap {
logger.debug("Current tokens: " + JSON.stringify(this.tokenStore.getAll())); logger.debug("Current tokens: " + JSON.stringify(this.tokenStore.getAll()));
return this.tokenStore.get(token); return this.tokenStore.get(token);
} }
associateCredentialsForToken(token: string, fullSmapiToken: SmapiToken, oldToken?:string) { associateCredentialsForToken(token: string, fullSmapiToken: SmapiToken) {
logger.debug("Adding token: " + token + " " + JSON.stringify(fullSmapiToken)); logger.debug("Adding token: " + token + " " + JSON.stringify(fullSmapiToken));
if(oldToken) { // Don't immediately delete old token to avoid race conditions
this.tokenStore.delete(oldToken); // The cleanup process will handle expired tokens later
}
this.tokenStore.set(token, fullSmapiToken); this.tokenStore.set(token, fullSmapiToken);
} }
} }
@@ -488,11 +487,9 @@ function bindSmapiSoapServiceToExpress(
const swapToken = (expiredToken: string | undefined) => (newToken: SmapiToken) => { const swapToken = (expiredToken: string | undefined) => (newToken: SmapiToken) => {
logger.debug("oldToken: " + expiredToken); logger.debug("oldToken: " + expiredToken);
logger.debug("newToken: " + JSON.stringify(newToken)); logger.debug("newToken: " + JSON.stringify(newToken));
if (expiredToken) { // Always add the new token, but don't immediately delete the old one
sonosSoap.associateCredentialsForToken(newToken.token, newToken, expiredToken); // to avoid race conditions where Sonos might still be using the old token
} else {
sonosSoap.associateCredentialsForToken(newToken.token, newToken); sonosSoap.associateCredentialsForToken(newToken.token, newToken);
}
return TE.right(newToken); return TE.right(newToken);
} }