Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • updated oauth providers that had unstable reference IDs leading to duplicate oauth records

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)

@vercel
Copy link

vercel bot commented Dec 18, 2025

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

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Dec 18, 2025 4:40am

@waleedlatif1 waleedlatif1 marked this pull request as ready for review December 18, 2025 04:04
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 18, 2025

Greptile Summary

This PR fixes OAuth providers (Wealthbox, Slack, Webflow) that were generating unstable reference IDs, which caused duplicate credential records in the database.

Key Changes

  • Account creation logic: Modified to check only (userId, providerId) instead of (userId, providerId, accountId), allowing the system to replace existing credentials when a user reconnects to the same provider
  • Wealthbox: Changed from timestamp-based ID (wealthbox-${Date.now()}) to stable constant (wealthbox-user)
  • Slack: Now fetches team and user IDs from auth.test API to create stable identifier ({teamId}-{userId})
  • Webflow: Changed from timestamp-based fallback (webflow-${Date.now()}) to stable fallback (webflow-user)
  • OAuth modal: Added performance optimization using useMemo to prevent unnecessary re-computations and sort new scopes to the top

Issues Found

  • Minor email formatting issue in Wealthbox provider (missing hyphen removal in email generation)

Confidence Score: 4/5

  • This PR is safe to merge with one minor syntax fix needed
  • The core fix correctly addresses the duplicate OAuth record issue by using stable identifiers and updating the account creation logic. The Slack implementation properly fetches unique identifiers from the API. The only issue is a minor email formatting inconsistency in the Wealthbox provider that should be fixed for consistency.
  • apps/sim/lib/auth/auth.ts requires attention for the email formatting fix at line 738

Important Files Changed

Filename Overview
apps/sim/lib/auth/auth.ts Fixed OAuth provider reference IDs for Wealthbox, Slack, and Webflow to use stable identifiers; updated account creation logic to replace existing credentials per (userId, providerId) pair
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/credential-selector/components/oauth-required-modal.tsx Optimized scope display logic using useMemo to prevent unnecessary re-computations and sort new scopes to the top

Sequence Diagram

sequenceDiagram
    participant User
    participant App
    participant OAuth Provider
    participant Auth System
    participant Database

    User->>App: Connect OAuth service
    App->>OAuth Provider: Initiate OAuth flow
    OAuth Provider->>User: Request authorization
    User->>OAuth Provider: Grant access
    OAuth Provider->>Auth System: Return tokens & user data
    
    Auth System->>Auth System: getUserInfo() extracts stable identifier
    Note over Auth System: Wealthbox: 'wealthbox-user'<br/>Slack: '{teamId}-{userId}'<br/>Webflow: 'webflow-{userId}'
    
    Auth System->>Database: Check existing (userId, providerId)
    
    alt Existing credential found
        Database->>Auth System: Return existing account
        Auth System->>Database: Update accountId, tokens, scopes
        Note over Database: Replace credential for same provider
    else No existing credential
        Auth System->>Database: Create new account record
        Note over Database: Store with stable accountId
    end
    
    Database->>Auth System: Success
    Auth System->>App: OAuth connected
    App->>User: Show success message
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1
Copy link
Collaborator Author

@greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@waleedlatif1 waleedlatif1 merged commit 471cb47 into staging Dec 18, 2025
11 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/creds branch December 18, 2025 04:45
waleedlatif1 added a commit that referenced this pull request Dec 18, 2025
…eading to duplicate oauth records (#2441)

* fix(oauth): updated oauth providers that had unstable reference IDs leading to duplicate oauth records

* ack PR comments
waleedlatif1 added a commit that referenced this pull request Dec 18, 2025
…n, developer, and custom domain salesforce orgs (#2441) (#2444)

* fix(oauth): updated oauth providers that had unstable reference IDs leading to duplicate oauth records (#2441)

* fix(oauth): updated oauth providers that had unstable reference IDs leading to duplicate oauth records

* ack PR comments

* ack PR comments

* cleanup salesforce refresh logic

* ack more PR comments
waleedlatif1 added a commit that referenced this pull request Dec 18, 2025
…roduction, developer, and custom domain salesforce orgs (#2441) (#2444)"

This reverts commit 9da19e8.
waleedlatif1 added a commit that referenced this pull request Dec 18, 2025
…roduction, developer, and custom domain salesforce orgs (#2441) (#2444)" (#2453)

This reverts commit 9da19e8.
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.

3 participants