Fix token store

This commit is contained in:
Wolfgang Kulhanek
2025-10-16 11:20:55 +02:00
parent fee5f74a2c
commit 9609cbd7f0
2 changed files with 25 additions and 4 deletions

View File

@@ -423,17 +423,31 @@ function bindSmapiSoapServiceToExpress(
E.chain((credentials) => {
// Check if token/key is associated with a user
const smapiToken = sonosSoap.getCredentialsForToken(credentials.loginToken.token);
if (!smapiToken || smapiToken.key !== credentials.loginToken.key) {
return E.left(new InvalidTokenError("Token not associated with any user"));
if (!smapiToken) {
return E.left(new InvalidTokenError("Token not found"));
}
// If credentials don't have a key, use the stored one
const effectiveKey = credentials.loginToken.key || smapiToken.key;
if (smapiToken.key !== effectiveKey) {
return E.left(new InvalidTokenError("Token key mismatch"));
}
return pipe(
smapiAuthTokens.verify({
token: credentials.loginToken.token,
key: credentials.loginToken.key,
key: effectiveKey,
}),
E.map((serviceToken) => ({
serviceToken,
credentials,
credentials: {
...credentials,
loginToken: {
...credentials.loginToken,
key: effectiveKey,
},
},
}))
);
}),