-
Notifications
You must be signed in to change notification settings - Fork 409
feat(clerk-js): Redirect on session exists during sign-in #7156
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 6 commits
b747bf7
2cb3122
2eb6101
15e0643
a57c28d
e8c45d9
631e48d
90f78cd
7034f0c
d8fa8fa
c69e7ba
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': minor | ||
| --- | ||
|
|
||
| When a session already exists on sign in, complete the sign in and redirect instead of only rendering an error. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -150,4 +150,67 @@ testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })('sign in f | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await u.po.expect.toBeSignedIn(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| test('redirects when attempting to sign in with existing session in another tab', async ({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| page, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| context, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| browser, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const u = createTestUtils({ app, page, context, browser }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Open sign-in page in both tabs before signing in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await u.po.signIn.goTo(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let secondTabUtils: any; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await u.tabs.runInNewTab(async u2 => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| secondTabUtils = u2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await u2.po.signIn.goTo(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Sign in on the first tab | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await u.po.signIn.setIdentifier(fakeUser.email); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await u.po.signIn.continue(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await u.po.signIn.setPassword(fakeUser.password); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await u.po.signIn.continue(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await u.po.expect.toBeSignedIn(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Attempt to sign in on the second tab (which already has sign-in mounted) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await secondTabUtils.po.signIn.setIdentifier(fakeUser.email); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await secondTabUtils.po.signIn.continue(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await secondTabUtils.po.signIn.setPassword(fakeUser.password); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await secondTabUtils.po.signIn.continue(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Should redirect and be signed in without error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await secondTabUtils.po.expect.toBeSignedIn(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| test('redirects when attempting to sign in with existing session in another tab', async ({ | |
| page, | |
| context, | |
| browser, | |
| }) => { | |
| const u = createTestUtils({ app, page, context, browser }); | |
| // Open sign-in page in both tabs before signing in | |
| await u.po.signIn.goTo(); | |
| let secondTabUtils: any; | |
| await u.tabs.runInNewTab(async u2 => { | |
| secondTabUtils = u2; | |
| await u2.po.signIn.goTo(); | |
| }); | |
| // Sign in on the first tab | |
| await u.po.signIn.setIdentifier(fakeUser.email); | |
| await u.po.signIn.continue(); | |
| await u.po.signIn.setPassword(fakeUser.password); | |
| await u.po.signIn.continue(); | |
| await u.po.expect.toBeSignedIn(); | |
| // Attempt to sign in on the second tab (which already has sign-in mounted) | |
| await secondTabUtils.po.signIn.setIdentifier(fakeUser.email); | |
| await secondTabUtils.po.signIn.continue(); | |
| await secondTabUtils.po.signIn.setPassword(fakeUser.password); | |
| await secondTabUtils.po.signIn.continue(); | |
| // Should redirect and be signed in without error | |
| await secondTabUtils.po.expect.toBeSignedIn(); | |
| }); | |
| test('redirects when attempting to sign in with existing session in another tab', async ({ | |
| page, | |
| context, | |
| browser, | |
| }) => { | |
| const u = createTestUtils({ app, page, context, browser }); | |
| // Open sign-in page in both tabs before signing in | |
| await u.po.signIn.goTo(); | |
| let secondTabUtils: Awaited<ReturnType<typeof u.tabs.runInNewTab>>; | |
| await u.tabs.runInNewTab(async u2 => { | |
| secondTabUtils = u2; | |
| await u2.po.signIn.goTo(); | |
| }); | |
| // Sign in on the first tab | |
| await u.po.signIn.setIdentifier(fakeUser.email); | |
| await u.po.signIn.continue(); | |
| await u.po.signIn.setPassword(fakeUser.password); | |
| await u.po.signIn.continue(); | |
| await u.po.expect.toBeSignedIn(); | |
| // Attempt to sign in on the second tab (which already has sign-in mounted) | |
| await secondTabUtils.po.signIn.setIdentifier(fakeUser.email); | |
| await secondTabUtils.po.signIn.continue(); | |
| await secondTabUtils.po.signIn.setPassword(fakeUser.password); | |
| await secondTabUtils.po.signIn.continue(); | |
| // Should redirect and be signed in without error | |
| await secondTabUtils.po.expect.toBeSignedIn(); | |
| }); |
🤖 Prompt for AI Agents
In integration/tests/sign-in-flow.test.ts around lines 154 to 185,
secondTabUtils is currently declared with the `any` type (line 164); change it
to the concrete TestUtils type instead of `any` — type it the same as `u` (e.g.,
use `typeof u` or `ReturnType<typeof createTestUtils>`), ensuring any necessary
types are imported or inferred so the variable is strongly typed for the
runInNewTab callback.
Outdated
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 | 🟠 Major
Avoid any type for secondTabUtils.
Line 197 declares secondTabUtils with any type, which violates the TypeScript coding guidelines.
Apply this diff to properly type the variable:
- let secondTabUtils: any;
+ let secondTabUtils: Awaited<ReturnType<typeof u.tabs.runInNewTab>>;
await u.tabs.runInNewTab(async u2 => {
secondTabUtils = u2;
await u2.po.signIn.goTo();
});As per coding guidelines.
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
integration/tests/sign-in-flow.test.ts around lines 187 to 215: the variable
secondTabUtils is declared as any on line 197; replace the any with the concrete
test-utils type (same as the local u) — e.g. declare secondTabUtils as
ReturnType<typeof createTestUtils> or typeof u so it has proper typing, and
ensure it is non-null when used (initialize to undefined with that type or
narrow/check before using) to satisfy TypeScript rules and the project coding
guidelines.
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 | 🟠 Major
Avoid
anytype forsecondTabUtils.Line 270 declares
secondTabUtilswithanytype, which violates the TypeScript coding guidelines. The return type ofcreateTestUtilsis complex but can be properly typed.Apply this diff to properly type the variable:
As per coding guidelines.
🤖 Prompt for AI Agents