Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/fix-csr-multisession-impersonation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@clerk/clerk-js': patch
---

Fix impersonation in CSR multi-session apps when admin has existing session

9 changes: 8 additions & 1 deletion packages/clerk-js/src/core/clerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,14 @@ export class Clerk implements ClerkInterface {
}

if (typeof session === 'string') {
session = (this.client.sessions.find(x => x.id === session) as SignedInSessionResource) || null;
const sessionId = session;
session = (this.client.sessions.find(x => x.id === sessionId) as SignedInSessionResource) || null;
// If session not found, reload client to fetch newly created sessions (e.g., impersonation sessions)
// This handles the case where setActive is called immediately after creating a session via ticket
if (!session) {
await this.client.fetch();
session = (this.client.sessions.find(x => x.id === sessionId) as SignedInSessionResource) || null;
}
}

const onBeforeSetActive: SetActiveHook =
Expand Down