Skip to content

fix(workspace): recover from stale sessions instead of blank loader after impersonation#5688

Merged
waleedlatif1 merged 3 commits into
stagingfrom
fix/impersonation-blank-loader
Jul 15, 2026
Merged

fix(workspace): recover from stale sessions instead of blank loader after impersonation#5688
waleedlatif1 merged 3 commits into
stagingfrom
fix/impersonation-blank-loader

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Fixes the blank screen at /workspace after switching or stopping impersonation (or letting an impersonation session expire) — previously the page rendered null forever when the workspaces query failed, with no recovery other than clearing browser data
  • /workspace now auto-recovers from the stale-cookie state: a 401 while the session still claims we're authenticated triggers a full sign-out (clears all auth cookies server-side) and redirects to login
  • Other load failures render an error card (Try again / Sign out) instead of a blank page; the fallback render is the spinner, never null
  • A transient session error no longer redirects to /login (middleware could bounce it straight back into a loop while the session cookie exists) — it shows the error card instead
  • Impersonation transitions (start in admin settings, stop in the banner) now run clearUserData() before navigating, so one identity's persisted client state (localStorage / Zustand persisted stores) can't leak into the next

Type of Change

  • Bug fix

Testing

Tested manually; tsc, biome, and check:api-validation pass

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

vercel Bot commented Jul 15, 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 Jul 15, 2026 5:15pm

Request Review

@cursor

cursor Bot commented Jul 15, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches auth recovery and sign-out on the workspace entry route and impersonation flows; incorrect handling could sign users out unexpectedly or leave stale client state.

Overview
Fixes the blank /workspace screen after impersonation ends, expires, or switches by handling stale auth (session looks logged in but APIs return 401) and by clearing per-user client state on identity changes.

/workspace now auto-recovers when the workspaces fetch 401s while the session still shows authenticated: full signOut, clearUserData(), then redirect to login. Other load failures show an error card (Try again / Sign out) instead of rendering nothing; a failed session query no longer blindly sends users to /login (which could loop with middleware while cookies remain).

Impersonation start (admin) and stop (banner) both await clearUserData() before window.location.assign('/workspace') so persisted Zustand/localStorage from one user does not leak into the next.

Reviewed by Cursor Bugbot for commit 81e74ae. Configure here.

Comment thread apps/sim/app/workspace/page.tsx Outdated
Comment thread apps/sim/app/workspace/page.tsx
@greptile-apps

greptile-apps Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR improves workspace recovery after impersonation and stale sessions. The main changes are:

  • Clears persisted user data when impersonation starts or stops.
  • Signs out stale authenticated sessions after workspace API authorization failures.
  • Shows retry and sign-out actions when workspace or session loading fails.
  • Keeps a loading indicator while authentication and workspace redirects are pending.

Confidence Score: 5/5

The latest changes look safe to merge.

  • Failed sign-out requests remain on the workspace error state instead of navigating.
  • Successful recovery clears client state before redirecting.
  • No additional blocking issue met the follow-up review scope.

Important Files Changed

Filename Overview
apps/sim/app/workspace/page.tsx Adds stale-session recovery, guarded sign-out handling, an error state, and a loading fallback.
apps/sim/app/workspace/[workspaceId]/components/impersonation-banner/impersonation-banner.tsx Clears persisted user state before navigating after impersonation stops.
apps/sim/app/workspace/[workspaceId]/settings/components/admin/admin.tsx Clears persisted user state before navigating after impersonation starts.

Reviews (3): Last reviewed commit: "fix(workspace): proceed with redirect wh..." | Re-trigger Greptile

Comment thread apps/sim/app/workspace/page.tsx
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/app/workspace/page.tsx
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@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.

✅ Bugbot reviewed your changes and found no new issues!

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

Reviewed by Cursor Bugbot for commit 81e74ae. Configure here.

@waleedlatif1
waleedlatif1 merged commit 4d0973f into staging Jul 15, 2026
18 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/impersonation-blank-loader branch July 15, 2026 17:24
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