-
Notifications
You must be signed in to change notification settings - Fork 419
feat(js,shared,ui): Support needs_client_trust sign-in status
#7430
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
6 commits
Select commit
Hold shift + click to select a range
21f4873
feat: Handle needs_client_trust status
tmilewski 3eedc43
chore: Handle needs_client_trust per email links
tmilewski 77c86a3
chore: Extract out common functionality
tmilewski 0363a1e
chore: Move helpers; More-generic typing
tmilewski e7c5f92
chore: Add changeset
tmilewski d6e048a
test(testing,ui): Add Client Trust tests; Handle two factor attempt/p…
tmilewski 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
Some comments aren't visible on the classic Files Changed page.
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/ui': minor | ||
| --- | ||
|
|
||
| Adds `SignInClientTrust` component for discretely handling flows where client trust is required. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import { expect, test } from '@playwright/test'; | ||
|
|
||
| import { appConfigs } from '../presets'; | ||
| import type { FakeUser } from '../testUtils'; | ||
| import { createTestUtils, testAgainstRunningApps } from '../testUtils'; | ||
|
|
||
| testAgainstRunningApps({ withEnv: [appConfigs.envs.withNeedsClientTrust] })( | ||
| 'client trust flow @generic @nextjs', | ||
| ({ app }) => { | ||
| test.describe.configure({ mode: 'serial' }); | ||
|
|
||
| let fakeUser: FakeUser; | ||
|
|
||
| test.beforeAll(async () => { | ||
| const u = createTestUtils({ app }); | ||
| fakeUser = u.services.users.createFakeUser(); | ||
| await u.services.users.createBapiUser(fakeUser); | ||
| }); | ||
|
|
||
| test.afterAll(async () => { | ||
| await fakeUser.deleteIfExists(); | ||
| await app.teardown(); | ||
| }); | ||
tmilewski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| test('sign in with email and password results in needs_client_trust', async ({ page, context }) => { | ||
| const u = createTestUtils({ app, page, context }); | ||
|
|
||
| // Sign in with a new device | ||
| await u.po.signIn.goTo(); | ||
| await u.po.signIn.setIdentifier(fakeUser.email); | ||
| await u.po.signIn.continue(); | ||
| await u.po.signIn.setPassword(fakeUser.password); | ||
| await u.po.signIn.continue(); | ||
|
|
||
| // After password is correctly entered, should navigate to client-trust route | ||
| // This verifies that the sign-in status is 'needs_client_trust' | ||
| await u.page.waitForURL(/\/sign-in\/client-trust/); | ||
|
|
||
| // Should contain the new device verification notice | ||
| await expect(u.page.getByText("You're signing in from a new device.")).toBeVisible(); | ||
|
|
||
| // User should not be signed in yet since client trust step is required | ||
| await u.po.expect.toBeSignedOut(); | ||
|
|
||
| await u.po.signIn.enterTestOtpCode(); | ||
| await u.po.expect.toBeSignedIn(); | ||
|
|
||
| await u.po.userButton.toggleTrigger(); | ||
| await u.po.userButton.waitForPopover(); | ||
| await u.po.userButton.triggerSignOut(); | ||
|
|
||
| await u.po.expect.toBeSignedOut(); | ||
|
|
||
| await u.po.signIn.goTo(); | ||
| await u.po.signIn.signInWithEmailAndInstantPassword({ | ||
| email: fakeUser.email, | ||
| password: fakeUser.password, | ||
| }); | ||
|
|
||
| // Sign in again with a now "known" device | ||
| await u.po.expect.toBeSignedIn(); | ||
| }); | ||
| }, | ||
| ); | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { withCardStateProvider } from '@/ui/elements/contexts'; | ||
| import { LoadingCard } from '@/ui/elements/LoadingCard'; | ||
|
|
||
| import { withRedirectToAfterSignIn, withRedirectToSignInTask } from '../../common'; | ||
| import { useCoreSignIn } from '../../contexts'; | ||
| import { SignInFactorTwoAlternativeMethods } from './SignInFactorTwoAlternativeMethods'; | ||
| import { SignInFactorTwoEmailCodeCard } from './SignInFactorTwoEmailCodeCard'; | ||
| import { SignInFactorTwoEmailLinkCard } from './SignInFactorTwoEmailLinkCard'; | ||
| import { SignInFactorTwoPhoneCodeCard } from './SignInFactorTwoPhoneCodeCard'; | ||
| import { useSecondFactorSelection } from './useSecondFactorSelection'; | ||
|
|
||
| function SignInClientTrustInternal(): JSX.Element { | ||
| const signIn = useCoreSignIn(); | ||
| const { | ||
| currentFactor, | ||
| factorAlreadyPrepared, | ||
| handleFactorPrepare, | ||
| selectFactor, | ||
| showAllStrategies, | ||
| toggleAllStrategies, | ||
| } = useSecondFactorSelection(signIn.supportedSecondFactors); | ||
|
|
||
| if (!currentFactor) { | ||
| return <LoadingCard />; | ||
| } | ||
|
|
||
| if (showAllStrategies) { | ||
| return ( | ||
| <SignInFactorTwoAlternativeMethods | ||
| onBackLinkClick={toggleAllStrategies} | ||
| onFactorSelected={selectFactor} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| switch (currentFactor?.strategy) { | ||
| case 'phone_code': | ||
| return ( | ||
| <SignInFactorTwoPhoneCodeCard | ||
| showClientTrustNotice | ||
| factorAlreadyPrepared={factorAlreadyPrepared} | ||
| onFactorPrepare={handleFactorPrepare} | ||
| factor={currentFactor} | ||
| onShowAlternativeMethodsClicked={toggleAllStrategies} | ||
| /> | ||
| ); | ||
| case 'email_code': | ||
| return ( | ||
| <SignInFactorTwoEmailCodeCard | ||
| showClientTrustNotice | ||
| factorAlreadyPrepared={factorAlreadyPrepared} | ||
| onFactorPrepare={handleFactorPrepare} | ||
| factor={currentFactor} | ||
| onShowAlternativeMethodsClicked={toggleAllStrategies} | ||
| /> | ||
| ); | ||
| case 'email_link': | ||
| return ( | ||
| <SignInFactorTwoEmailLinkCard | ||
| showClientTrustNotice | ||
| factorAlreadyPrepared={factorAlreadyPrepared} | ||
| onFactorPrepare={handleFactorPrepare} | ||
| factor={currentFactor} | ||
| onShowAlternativeMethodsClicked={toggleAllStrategies} | ||
| /> | ||
| ); | ||
| default: | ||
| return <LoadingCard />; | ||
| } | ||
| } | ||
|
|
||
| export const SignInClientTrust = withRedirectToSignInTask( | ||
| withRedirectToAfterSignIn(withCardStateProvider(SignInClientTrustInternal)), | ||
| ); |
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
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.
Uh oh!
There was an error while loading. Please reload this page.