Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions apps/api/src/cloud-security/cloud-security.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ export class CloudSecurityService {
};
}

// Check if token needs refresh
const needsRefresh =
await this.credentialVaultService.needsRefresh(connectionId);
this.logger.log(
`Token refresh check for ${providerSlug}: needsRefresh=${needsRefresh}`,
);

// Get valid access token (with refresh if needed)
const accessToken =
await this.credentialVaultService.getValidAccessToken(connectionId, {
Expand All @@ -108,6 +115,9 @@ export class CloudSecurityService {
});

if (!accessToken) {
this.logger.error(
`Failed to get valid access token for ${providerSlug} connection ${connectionId}`,
);
return {
success: false,
provider: providerSlug,
Expand All @@ -117,6 +127,10 @@ export class CloudSecurityService {
};
}

this.logger.log(
`Using ${needsRefresh ? 'refreshed' : 'existing'} access token for ${providerSlug}`,
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Misleading log message after failed token refresh

The log message uses the needsRefresh variable captured earlier to determine whether to say "refreshed" or "existing" token. However, getValidAccessToken can fail to refresh and fall back to returning the existing token. In this case, needsRefresh would be true but the actual token returned is the existing (not refreshed) one. The log would incorrectly say "Using refreshed access token" when it's actually the existing potentially-expiring token.

Fix in Cursor Fix in Web


// Get full credentials and update with fresh access token
const decrypted =
await this.credentialVaultService.getDecryptedCredentials(
Expand Down