-
Notifications
You must be signed in to change notification settings - Fork 381
fix(clerk-js): Correct signout behavior for multisession #6515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
1d77806
bcbbbd4
a5999e3
7362dd2
ab7eae9
6fbce92
03a8ac0
21791b7
07a5851
763fb5a
3d24960
13971e8
f59bdaa
a9029ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@clerk/clerk-js': patch | ||
--- | ||
|
||
Fixing redirect behavior when signing out from a multisession app with multple singed in accounts |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -809,6 +809,42 @@ describe('Clerk singleton', () => { | |
expect(sut.navigate).toHaveBeenCalledWith('/after-sign-out'); | ||
}); | ||
}); | ||
|
||
it('properly restores auth state from remaining sessions after multisession sign-out', async () => { | ||
const mockClient = { | ||
signedInSessions: [mockSession1, mockSession2], | ||
sessions: [mockSession1, mockSession2], | ||
destroy: mockClientDestroy, | ||
lastActiveSessionId: '1', | ||
}; | ||
|
||
mockSession1.remove = jest.fn().mockImplementation(() => { | ||
mockClient.signedInSessions = mockClient.signedInSessions.filter(s => s.id !== '1'); | ||
mockClient.sessions = mockClient.sessions.filter(s => s.id !== '1'); | ||
return Promise.resolve(mockSession1); | ||
}); | ||
|
||
mockClientFetch.mockReturnValue(Promise.resolve(mockClient)); | ||
|
||
const sut = new Clerk(productionPublishableKey); | ||
sut.navigate = jest.fn(); | ||
await sut.load(); | ||
|
||
expect(sut.session).toBe(mockSession1); | ||
expect(sut.isSignedIn).toBe(true); | ||
|
||
await sut.signOut({ sessionId: '1' }); | ||
|
||
await waitFor(() => { | ||
expect(mockSession1.remove).toHaveBeenCalled(); | ||
expect(mockClientDestroy).not.toHaveBeenCalled(); | ||
expect(sut.navigate).toHaveBeenCalledWith('/'); | ||
}); | ||
|
||
expect(mockClient.lastActiveSessionId).toBe('2'); | ||
expect(sut.session).toBe(mockSession2); | ||
expect(sut.isSignedIn).toBe(true); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add assertions for cookie/token sync and event emissions to prevent regressions To ensure reload consistency, assert that the next session’s token is propagated or that a TokenUpdate was emitted. Also validate that UserSignOut is not emitted when removing a non-current session. Examples:
I can draft these test additions if helpful. 🤖 Prompt for AI Agents
|
||
}); | ||
|
||
describe('.navigate(to)', () => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Great addition; add guard-rail tests for non-current removal and active session selection
This verifies the main regression. Please add:
Example additions you can append near this block:
🤖 Prompt for AI Agents