-
Notifications
You must be signed in to change notification settings - Fork 366
fix(clerk-js): Navigate to tasks when switching sessions #6273
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
81b6009
Navigate to tasks when switching sessions with `setActive`
LauraBeatris 8a71b72
Revalidate server state
LauraBeatris c8e724b
Add changeset
LauraBeatris c428009
Create user on every test block instead of on hook
LauraBeatris c290255
Remove duplicated test block between sign-in
LauraBeatris 1f929d6
Add E2E test for switching sessions with task
LauraBeatris 46cf927
Introduce separate suite for multi-session
LauraBeatris fe58e39
Add method to await for task to be mounted
LauraBeatris 3adbec7
Revalidate server state on `setActive` with pending session
LauraBeatris 46bf92f
Fix `SignIn` to use hash routing
LauraBeatris 7221d8f
Update organization slug to avoid colision
LauraBeatris 26448fc
Update bundlewatch
LauraBeatris 0a8fdea
Decrease flakyness when switching account
LauraBeatris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@clerk/clerk-js': patch | ||
--- | ||
|
||
Navigate to tasks when switching sessions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { test } from '@playwright/test'; | ||
|
||
import { appConfigs } from '../presets'; | ||
import type { FakeUser } from '../testUtils'; | ||
import { createTestUtils, testAgainstRunningApps } from '../testUtils'; | ||
|
||
testAgainstRunningApps({ withEnv: [appConfigs.envs.withSessionTasks] })( | ||
'session tasks multi-session flow @nextjs', | ||
({ app }) => { | ||
test.describe.configure({ mode: 'serial' }); | ||
|
||
let user1: FakeUser; | ||
let user2: FakeUser; | ||
|
||
test.beforeAll(async () => { | ||
const u = createTestUtils({ app }); | ||
|
||
user1 = u.services.users.createFakeUser(); | ||
user2 = u.services.users.createFakeUser(); | ||
|
||
await u.services.users.createBapiUser(user1); | ||
await u.services.users.createBapiUser(user2); | ||
}); | ||
|
||
test.afterAll(async () => { | ||
const u = createTestUtils({ app }); | ||
await user1.deleteIfExists(); | ||
await user2.deleteIfExists(); | ||
await u.services.organizations.deleteAll(); | ||
await app.teardown(); | ||
}); | ||
|
||
test.afterEach(async ({ page, context }) => { | ||
const u = createTestUtils({ app, page, context }); | ||
await u.page.signOut(); | ||
await u.page.context().clearCookies(); | ||
}); | ||
|
||
test('when switching sessions, navigate to task', async ({ page, context }) => { | ||
const u = createTestUtils({ app, page, context }); | ||
|
||
// Performs sign-in | ||
await u.po.signIn.goTo(); | ||
await u.po.signIn.setIdentifier(user1.email); | ||
await u.po.signIn.continue(); | ||
await u.po.signIn.setPassword(user1.password); | ||
await u.po.signIn.continue(); | ||
await u.po.expect.toBeSignedIn(); | ||
|
||
// Resolves task | ||
const fakeOrganization = Object.assign(u.services.organizations.createFakeOrganization(), { | ||
slug: u.services.organizations.createFakeOrganization().slug + '-with-session-tasks', | ||
}); | ||
|
||
await u.po.sessionTask.resolveForceOrganizationSelectionTask(fakeOrganization); | ||
await u.po.expect.toHaveResolvedTask(); | ||
|
||
// Navigates to after sign-in | ||
await u.page.waitForAppUrl('/'); | ||
|
||
// Create second user, to initiate a pending session | ||
// Don't resolve task and switch to active session afterwards | ||
await u.po.signIn.goTo(); | ||
await u.po.signIn.setIdentifier(user2.email); | ||
await u.po.signIn.continue(); | ||
await u.po.signIn.setPassword(user2.password); | ||
await u.po.signIn.continue(); | ||
|
||
// Sign-in again back with active session | ||
await u.po.signIn.goTo(); | ||
await u.po.signIn.setIdentifier(user1.email); | ||
await u.po.signIn.continue(); | ||
await u.po.signIn.setPassword(user1.password); | ||
await u.po.signIn.continue(); | ||
|
||
// Navigate to protected page, with active session, where user button gets rendered | ||
await u.page.goToRelative('/user-button'); | ||
|
||
// Switch account, to a session that has a pending status | ||
await u.po.userButton.waitForMounted(); | ||
await u.po.userButton.toggleTrigger(); | ||
await u.po.userButton.waitForPopover(); | ||
await u.po.userButton.toHaveVisibleMenuItems([/Manage account/i, /Sign out$/i]); | ||
await u.po.userButton.switchAccount(user2.email); | ||
|
||
// Resolve task | ||
await u.po.signIn.waitForMounted(); | ||
const fakeOrganization2 = u.services.organizations.createFakeOrganization(); | ||
await u.po.sessionTask.resolveForceOrganizationSelectionTask(fakeOrganization2); | ||
await u.po.expect.toHaveResolvedTask(); | ||
|
||
// Navigates to after sign-in | ||
await u.page.waitForAppUrl('/'); | ||
}); | ||
}, | ||
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We weren't revalidating the server state on
setActive
with a pendingsession
, fixing it now.