Skip to content

fix(notifications): credentials connection notifs showing up in right resource#3599

Merged
icecrasher321 merged 4 commits intostagingfrom
fix/cred-notifs
Mar 15, 2026
Merged

fix(notifications): credentials connection notifs showing up in right resource#3599
icecrasher321 merged 4 commits intostagingfrom
fix/cred-notifs

Conversation

@icecrasher321
Copy link
Collaborator

Summary

Need to redirect back to the right place with either workflow notification when connecting from a workflow block. Or using EMCN toast component when connecting from KB connector or directly from Integrations settings page.

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 Mar 15, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Mar 15, 2026 7:53am

Request Review

@cursor
Copy link

cursor bot commented Mar 15, 2026

PR Summary

Medium Risk
Changes post-OAuth return handling and navigation across Integrations/Workflow/KB pages using new sessionStorage context, which could misroute users or suppress notifications if the context logic is wrong.

Overview
Fixes OAuth connection/reconnect notifications showing up on the wrong screen by introducing a shared OAuthReturnContext stored in sessionStorage and consumed on return.

Integrations now routes back to the originating page (workflow or kb-connectors) after OAuth, while workflows show workflow-scoped notifications and KB connector pages show EMCN toast notifications. This replaces the old workflow-local sim.oauth-connect-pending logic, adds ToastProvider to the workspace layout, and ensures OAuth modals clear the stored return context on close.

Written by Cursor Bugbot for commit 5193687. Configure here.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 15, 2026

Greptile Summary

This PR fixes credential connection notifications being shown in the wrong place (always in the workflow notification panel, even when initiated from a KB connector or the integrations settings page). It introduces a typed OAuthReturnContext written to sessionStorage before the OAuth redirect, and three new hooks (useOAuthReturnRouter, useOAuthReturnForWorkflow, useOAuthReturnForKBConnectors) that route the post-OAuth notification to the correct surface. A ToastProvider wrapper is added to the workspace layout to enable toasts across KB and integrations pages.

Key changes:

  • lib/credentials/client-state.ts — new discriminated union type OAuthReturnContext and write/read/consume helpers replacing raw sessionStorage access
  • hooks/use-oauth-return.ts — three focused hooks centralizing post-OAuth notification/routing logic
  • integrations-manager.tsx — replaced ad-hoc sessionStorage writes with writeOAuthReturnContext; useOAuthReturnRouter now decides whether to stay on the page (integrations origin) or redirect (workflow / KB origins)
  • workflow.tsx — ~60-line inline useEffect replaced with useOAuthReturnForWorkflow
  • add-connector-modal.tsx / connectors-section.tsx — write context directly before opening local OAuth modal

Issues found:

  • preCount is set to the provider-scoped credential count in both add-connector-modal.tsx (line 297) and connectors-section.tsx (line 454), but resolveOAuthMessage compares against the total workspace OAuth credential count returned by the API. This mismatch means the "already connected" message path will never trigger in the KB connector flow — it will always display "connected successfully."

Confidence Score: 3/5

  • Safe to merge with a small follow-up fix — the core routing logic is sound, but the "already connected" detection is broken for all KB connector OAuth flows.
  • The primary goal of the PR (routing notifications to the correct surface) works correctly. The refactor to a typed context is clean and well-structured. However, preCount in both KB connector components is scoped to a single OAuth provider while resolveOAuthMessage compares against the total workspace OAuth count, so duplicate-connection detection never fires in those flows. This is a logic bug that produces a misleading success message, lowering the score from an otherwise clean refactor.
  • add-connector-modal.tsx and connectors-section.tsx — both pass a provider-scoped credential count as preCount which breaks the already-connected detection.

Important Files Changed

Filename Overview
apps/sim/hooks/use-oauth-return.ts New hook centralizing all post-OAuth return logic into three exports (router, workflow, KB connectors); minor concern around not consuming context before redirect for workflow/kb-connectors cases.
apps/sim/lib/credentials/client-state.ts Adds well-typed OAuthReturnContext discriminated union and CRUD helpers (writeOAuthReturnContext, readOAuthReturnContext, consumeOAuthReturnContext) backed by sessionStorage; clean implementation with expiry support.
apps/sim/app/workspace/[workspaceId]/knowledge/[id]/components/add-connector-modal/add-connector-modal.tsx Writes OAuthReturnContext before opening OAuth modal; preCount uses provider-scoped credential count instead of total workspace OAuth count, breaking the "already connected" detection in resolveOAuthMessage.
apps/sim/app/workspace/[workspaceId]/knowledge/[id]/components/connectors-section/connectors-section.tsx Same preCount scoping issue as add-connector-modal: uses provider-filtered credential count instead of total workspace OAuth count, so "already connected" message never fires for the "Update access" path.
apps/sim/app/workspace/[workspaceId]/settings/components/integrations/integrations-manager.tsx Replaces raw sessionStorage writes with writeOAuthReturnContext; correctly uses credentials.filter((c) => c.type === 'oauth').length for preCount; adds useOAuthReturnRouter hook and pendingReturnOriginRef for origin-aware routing.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx Replaces the ~60-line inline useEffect handling sim.oauth-connect-pending with a single useOAuthReturnForWorkflow(workflowIdParam) call; clean refactor with no functional regressions observed.
apps/sim/app/workspace/[workspaceId]/knowledge/[id]/base.tsx Minimal change: adds useOAuthReturnForKBConnectors(id) call to handle post-OAuth toasts on the KB page.
apps/sim/app/workspace/[workspaceId]/layout.tsx Wraps workspace layout with ToastProvider to enable toast notifications across the entire workspace, including the KB and integrations pages.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/credential-selector/credential-selector.tsx Adds returnOrigin (workflow ID) to the pending credential create request so integrations-manager can redirect back to the correct workflow after OAuth completes.

Sequence Diagram

sequenceDiagram
    participant WF as Workflow Block<br/>(credential-selector)
    participant KB as KB Connector<br/>(add-connector-modal / connectors-section)
    participant INT as Integrations Page<br/>(integrations-manager)
    participant SS as sessionStorage
    participant OA as OAuth Provider

    Note over WF: Flow 1 — from Workflow Block
    WF->>SS: writePendingCredentialCreateRequest<br/>{ returnOrigin: { type:'workflow', workflowId } }
    WF->>INT: navigateToSettings('integrations')
    INT->>SS: pendingReturnOriginRef ← request.returnOrigin
    INT->>SS: writeOAuthReturnContext<br/>{ origin:'workflow', workflowId }
    INT->>OA: connectOAuthService (callbackURL = integrations page)
    OA-->>INT: redirect back
    INT->>SS: readOAuthReturnContext → origin='workflow'
    INT->>WF: router.replace(…/w/workflowId)
    WF->>SS: consumeOAuthReturnContext
    WF->>WF: addNotification (workflow-scoped)

    Note over KB: Flow 2 — from KB Connector page
    KB->>SS: writeOAuthReturnContext<br/>{ origin:'kb-connectors', knowledgeBaseId }
    KB->>OA: connectOAuthService (callbackURL = KB page)
    OA-->>KB: redirect back
    KB->>SS: consumeOAuthReturnContext
    KB->>KB: toast.success(message)

    Note over INT: Flow 3 — from Integrations page directly
    INT->>SS: writeOAuthReturnContext<br/>{ origin:'integrations' }
    INT->>OA: connectOAuthService (callbackURL = integrations page)
    OA-->>INT: redirect back
    INT->>SS: consumeOAuthReturnContext
    INT->>INT: toast.success(message)
Loading

Last reviewed commit: 62e5b8a

@icecrasher321
Copy link
Collaborator Author

bugbot run

@icecrasher321
Copy link
Collaborator Author

bugbot run

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

@icecrasher321 icecrasher321 merged commit 8906439 into staging Mar 15, 2026
12 checks passed
@icecrasher321 icecrasher321 deleted the fix/cred-notifs branch March 15, 2026 08:01
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