Skip to content

fix(credentials): add cross-cache invalidation for oauth credential queries#4076

Merged
waleedlatif1 merged 1 commit intostagingfrom
waleedlatif1/credential-query-audit
Apr 9, 2026
Merged

fix(credentials): add cross-cache invalidation for oauth credential queries#4076
waleedlatif1 merged 1 commit intostagingfrom
waleedlatif1/credential-query-audit

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • When creating/updating/deleting workspace credentials (e.g. Google service accounts), also invalidate oauthCredentialKeys so credential-selector dropdowns update immediately
  • Switch all credential-set mutations from onSuccess to onSettled for reliable cache reconciliation

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 9, 2026

PR Summary

Low Risk
Low risk: changes are limited to React Query cache invalidation timing/coverage, but could cause extra refetches since invalidations now run even on failed mutations.

Overview
Fixes stale credential UI by invalidating oauthCredentials queries whenever workspace credentials are created/updated/deleted, ensuring OAuth-backed credential selectors refresh immediately.

Updates all credential-set mutations to use onSettled (instead of onSuccess) so related membership/invitation/list caches are invalidated reliably even when a mutation errors.

Reviewed by Cursor Bugbot for commit ca32a83. Configure here.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 9, 2026 6:23pm

Request Review

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 9, 2026

Greptile Summary

This PR adds cross-cache invalidation so that workspace credential mutations (create, update, delete) also invalidate oauthCredentials queries, ensuring OAuth credential-selector dropdowns refresh immediately. It also migrates all credential-sets.ts mutation handlers from onSuccess to onSettled for consistent cache reconciliation on both success and error paths.

The OAUTH_CREDENTIALS_KEY constant (['oauthCredentials']) correctly matches oauthCredentialKeys.all from oauth/oauth-credentials.ts, and the duplication is clearly documented to explain the circular-import constraint.

Confidence Score: 5/5

Safe to merge — changes are additive cache invalidations and non-breaking lifecycle handler migrations.

All findings are P2 or below. The OAUTH_CREDENTIALS_KEY constant correctly mirrors oauthCredentialKeys.all, onSettled signatures are correct for all 8 mutations in credential-sets.ts, and the three new cross-cache invalidations are logically correct for credential CRUD operations. No logic errors, data loss, or security concerns found.

No files require special attention.

Vulnerabilities

No security concerns identified.

Important Files Changed

Filename Overview
apps/sim/hooks/queries/credentials.ts Adds OAUTH_CREDENTIALS_KEY constant and cross-cache invalidation to useCreateWorkspaceCredential, useUpdateWorkspaceCredential, and useDeleteWorkspaceCredential; key value correctly matches oauthCredentialKeys.all.
apps/sim/hooks/queries/credential-sets.ts Switches 8 credential-set mutation handlers from onSuccess to onSettled for reliable cache reconciliation; parameter signatures correctly updated to include _error.

Sequence Diagram

sequenceDiagram
    participant UI as Credential UI
    participant Mutation as useCreate/Update/DeleteWorkspaceCredential
    participant QC as QueryClient
    participant WC as workspaceCredential queries
    participant OC as oauthCredentials queries

    UI->>Mutation: mutate(payload)
    Mutation->>API: POST/PUT/DELETE /api/credentials
    API-->>Mutation: response
    Note over Mutation: onSettled (success or error)
    Mutation->>QC: invalidateQueries(workspaceCredentialKeys.lists())
    QC->>WC: refetch
    Mutation->>QC: invalidateQueries(['oauthCredentials'])
    QC->>OC: refetch
    OC-->>UI: credential-selector dropdowns update
Loading

Reviews (1): Last reviewed commit: "fix(credentials): add cross-cache invali..." | Re-trigger Greptile

@waleedlatif1 waleedlatif1 merged commit 7bd271a into staging Apr 9, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant