Skip to content

fix(credentials): restore reliable OAuth connections - #6753

Merged
TheodoreSpeaks merged 3 commits into
stagingfrom
fix/connected-integrations-list
Aug 16, 2026
Merged

fix(credentials): restore reliable OAuth connections#6753
TheodoreSpeaks merged 3 commits into
stagingfrom
fix/connected-integrations-list

Conversation

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator

Summary

  • preserve credential draft state across the Better Auth account lifecycle
  • let new OAuth attempts supersede stale drafts while invalidating older callbacks
  • handle already-connected provider accounts idempotently and report verified outcomes

Type of Change

  • Bug fix

Testing

  • 487 credential and OAuth tests passed during development
  • focused post-resync suite: 22 tests passed
  • TypeScript, lint, API validation, block-registry checks, and all 27 repository audits passed

Checklist

  • Code follows project style guidelines
  • Self-reviewed the changes
  • Tests added or updated and passing
  • No new warnings introduced
  • Branch is synchronized with staging

@vercel

vercel Bot commented Aug 16, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Aug 16, 2026 12:34am

Request Review

@cursor

cursor Bot commented Aug 16, 2026

Copy link
Copy Markdown

PR Summary

High Risk
Changes touch OAuth callback handling, credential creation, and desktop handoff paths; mis-binding or stricter after-hook failures could block or mis-attach workspace credentials.

Overview
This PR tightens OAuth credential linking so each launch binds to an exact draft id, survives Better Auth’s deferred account hooks, and reports verified outcomes instead of optimistic success toasts.

Draft lifecycle: createConnectDraft now rotates the draft primary key on conflict instead of only refreshing TTL, so a newer connect invalidates stale callbacks. The draft API returns draftId, and web/desktop flows pass draftId / credentialDraftId through connect URLs, OAuth callbackURL, and desktop handoff IPC (with validation).

Better Auth: Draft binding is captured in account.create.before on OAuth callbacks and consumed in the after-hook via request-scoped storage, fixing lost state when processing is deferred. OAuth callbacks without a captured binding fail rather than silently skipping draft processing.

Idempotency & UX: Duplicate workspace+account inserts are handled as reconnect (bump updatedAt, audit) instead of being ignored. Post-OAuth messaging compares baseline credentials (accountId / updatedAt) and can show errors when verification fails; explicit reconnect: true paths keep reconnect success without a baseline. displayNameDefinesIntent and active-draft conflict errors are removed.

Reviewed by Cursor Bugbot for commit 25f6ba9. Bugbot is set up for automated code reviews on this repo. Configure here.

@TheodoreSpeaks
TheodoreSpeaks force-pushed the fix/connected-integrations-list branch from 44eb3c1 to 5139056 Compare August 16, 2026 00:19
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

@greptile-apps

greptile-apps Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR carries exact credential-draft state through browser and desktop OAuth flows, lets newer launches supersede stale drafts, and verifies idempotent account connections. The new timestamp-based verification can still attribute an unrelated credential update to the current OAuth attempt.

  • Propagates draft IDs through desktop IPC, handoff URLs, and OAuth callback state.
  • Captures credential-draft state across Better Auth account hooks.
  • Handles workspace/account conflicts idempotently and adds return-result verification.

Confidence Score: 4/5

The PR should not merge until OAuth return verification can distinguish the current authorization from unrelated credential timestamp updates.

The return path currently treats any post-launch updatedAt change on a same-provider credential as proof of this OAuth attempt, so concurrent edits or authorizations can produce a verified success for a failed or abandoned flow.

Files Needing Attention: apps/sim/hooks/use-oauth-return.ts

Important Files Changed

Filename Overview
apps/sim/hooks/use-oauth-return.ts Adds structured success/error reporting and baseline verification, but a mutable updatedAt delta can falsely verify an unrelated operation as this attempt’s success.
apps/sim/lib/credentials/draft-hooks.ts Handles the exact workspace/account conflict idempotently and updates the existing credential timestamp used by return verification.
apps/sim/lib/credentials/draft-processor.ts Preserves request-scoped draft binding across Better Auth account hooks and consumes exact draft IDs.
apps/sim/hooks/queries/oauth/oauth-connections.ts Propagates draft IDs through special-provider, desktop, and browser OAuth launch paths.
apps/desktop/src/main/handoff.ts Carries the validated exact draft ID through the single-use desktop OAuth handoff.

Sequence Diagram

sequenceDiagram
  participant UI as Workspace UI
  participant OAuth as OAuth Provider
  participant Auth as Better Auth Callback
  participant DB as Credential Store
  UI->>UI: Snapshot credential IDs/account IDs/updatedAt
  UI->>OAuth: Launch OAuth with exact draft ID
  OAuth->>Auth: Provider callback
  Auth->>DB: Create, reconnect, or bump existing credential
  Auth-->>UI: Return to application
  UI->>DB: Reload workspace credentials
  UI->>UI: Infer outcome from count/accountId/updatedAt delta
Loading

Reviews (4): Last reviewed commit: "fix(credentials): preserve reauthorizati..." | Re-trigger Greptile

Comment thread apps/sim/hooks/use-oauth-return.ts Outdated
Comment thread apps/sim/hooks/use-oauth-return.ts
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@cursor review

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@cursor review

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 2403a8d. Configure here.

Comment thread apps/sim/hooks/use-oauth-return.ts
Comment thread apps/sim/hooks/use-oauth-return.ts

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 25f6ba9. Configure here.

Comment thread apps/sim/hooks/use-oauth-return.ts
@TheodoreSpeaks
TheodoreSpeaks merged commit 623c30f into staging Aug 16, 2026
30 checks passed
@TheodoreSpeaks
TheodoreSpeaks deleted the fix/connected-integrations-list branch August 16, 2026 00:43
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