-
Notifications
You must be signed in to change notification settings - Fork 453
feat(clerk-js): Use passkey as first factor in <SignIn/>
#3000
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
16 commits
Select commit
Hold shift + click to select a range
ff99500
feat(clerk-js): WIP SignIn with UI
panteliselef c4a87a4
chore(clerk-js): Cleanup
panteliselef 56096de
chore(clerk-js): Refactor shared code
panteliselef 55ed2ce
chore(clerk-js): Bring back isWebAuthnAutofillSupported
panteliselef b07c941
chore(clerk-js): Display "Use passkey instead"
panteliselef 7acdf6f
chore(clerk-js): Improve conditional calling of `create`
panteliselef de86a27
chore(clerk-js): Remove preferredSignInStrategy mock
panteliselef 824ddf2
feat(clerk-js): Add fingerprint icon
panteliselef 28b3c8b
chore(clerk-js): Add changeset
panteliselef c10a27c
fix(clerk-js): Add localized text
panteliselef c173982
chore(clerk-js): Improve abort error
panteliselef d1d3821
chore(clerk-js): Fix build
panteliselef 4104a02
fix(clerk-js): Remove mocks to allow tests to run
panteliselef eec17d2
fix(clerk-js): Remove mocks to allow tests to run
panteliselef ca8834b
feat(clerk-js): Add passkey settings from environment
panteliselef 7163d99
fix(clerk-js): Correctly call authenticatePasskey for the appropriate…
panteliselef 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,6 @@ | ||
| --- | ||
| '@clerk/clerk-js': minor | ||
| '@clerk/types': minor | ||
| --- | ||
|
|
||
| Allow users to authenticate with passkeys via the `<SignIn/>`. |
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
91 changes: 91 additions & 0 deletions
91
packages/clerk-js/src/ui/components/SignIn/SignInFactorOnePasskey.tsx
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,91 @@ | ||
| import type { ResetPasswordCodeFactor } from '@clerk/types'; | ||
| import React from 'react'; | ||
|
|
||
| import { useCoreSignIn } from '../../contexts'; | ||
| import { descriptors, Flex, Flow, Icon, localizationKeys } from '../../customizables'; | ||
| import { Card, Form, Header, IdentityPreview, useCardState } from '../../elements'; | ||
| import { Fingerprint } from '../../icons'; | ||
| import { useRouter } from '../../router/RouteContext'; | ||
| import { HavingTrouble } from './HavingTrouble'; | ||
| import { useHandleAuthenticateWithPasskey } from './shared'; | ||
|
|
||
| type SignInFactorOnePasswordProps = { | ||
| onShowAlternativeMethodsClick: React.MouseEventHandler | undefined; | ||
| onFactorPrepare: (f: ResetPasswordCodeFactor) => void; | ||
| }; | ||
|
|
||
| export const SignInFactorOnePasskey = (props: SignInFactorOnePasswordProps) => { | ||
| const { onShowAlternativeMethodsClick } = props; | ||
| const card = useCardState(); | ||
| const signIn = useCoreSignIn(); | ||
| const { navigate } = useRouter(); | ||
| const [showHavingTrouble, setShowHavingTrouble] = React.useState(false); | ||
| const toggleHavingTrouble = React.useCallback(() => setShowHavingTrouble(s => !s), [setShowHavingTrouble]); | ||
| const authenticateWithPasskey = useHandleAuthenticateWithPasskey(); | ||
|
|
||
| const goBack = () => { | ||
| return navigate('../'); | ||
| }; | ||
|
|
||
| const handleSubmit: React.FormEventHandler = e => { | ||
| e.preventDefault(); | ||
| return authenticateWithPasskey(); | ||
| }; | ||
|
|
||
| if (showHavingTrouble) { | ||
| return <HavingTrouble onBackLinkClick={toggleHavingTrouble} />; | ||
| } | ||
|
|
||
| return ( | ||
| <Flow.Part part='password'> | ||
| <Card.Root> | ||
| <Card.Content> | ||
| <Header.Root showLogo> | ||
| <Icon | ||
| elementDescriptor={descriptors.passkeyIcon} | ||
| icon={Fingerprint} | ||
| sx={t => ({ | ||
| color: t.colors.$neutralAlpha500, | ||
| marginInline: 'auto', | ||
| paddingBottom: t.sizes.$1, | ||
| width: t.sizes.$12, | ||
| height: t.sizes.$12, | ||
| })} | ||
| /> | ||
| <Header.Title localizationKey={localizationKeys('signIn.passkey.title')} /> | ||
| <Header.Subtitle localizationKey={localizationKeys('signIn.passkey.subtitle')} /> | ||
| <IdentityPreview | ||
| identifier={signIn.identifier} | ||
| avatarUrl={signIn.userData.imageUrl} | ||
| onClick={goBack} | ||
| /> | ||
| </Header.Root> | ||
| <Card.Alert>{card.error}</Card.Alert> | ||
| <Flex | ||
| direction='col' | ||
| elementDescriptor={descriptors.main} | ||
| gap={4} | ||
| > | ||
| <Form.Root | ||
| onSubmit={handleSubmit} | ||
| gap={8} | ||
| > | ||
| <Form.SubmitButton hasArrow /> | ||
| </Form.Root> | ||
| <Card.Action elementId={onShowAlternativeMethodsClick ? 'alternativeMethods' : 'havingTrouble'}> | ||
| <Card.ActionLink | ||
| localizationKey={localizationKeys( | ||
| onShowAlternativeMethodsClick | ||
| ? 'footerActionLink__useAnotherMethod' | ||
| : 'signIn.alternativeMethods.actionLink', | ||
| )} | ||
| onClick={onShowAlternativeMethodsClick || toggleHavingTrouble} | ||
| /> | ||
| </Card.Action> | ||
| </Flex> | ||
| </Card.Content> | ||
| <Card.Footer /> | ||
| </Card.Root> | ||
| </Flow.Part> | ||
| ); | ||
| }; | ||
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,52 @@ | ||
| import { isClerkRuntimeError, isUserLockedError } from '@clerk/shared/error'; | ||
| import { useClerk } from '@clerk/shared/react'; | ||
| import { useCallback, useEffect } from 'react'; | ||
|
|
||
| import { clerkInvalidFAPIResponse } from '../../../core/errors'; | ||
| import { __internal_WebAuthnAbortService } from '../../../utils/passkeys'; | ||
| import { useCoreSignIn, useSignInContext } from '../../contexts'; | ||
| import { useCardState } from '../../elements'; | ||
| import { useSupportEmail } from '../../hooks/useSupportEmail'; | ||
| import { useRouter } from '../../router'; | ||
| import { handleError } from '../../utils'; | ||
|
|
||
| function useHandleAuthenticateWithPasskey() { | ||
| const card = useCardState(); | ||
| const { setActive } = useClerk(); | ||
| const { navigate } = useRouter(); | ||
| const supportEmail = useSupportEmail(); | ||
| const { navigateAfterSignIn } = useSignInContext(); | ||
| const { __experimental_authenticateWithPasskey } = useCoreSignIn(); | ||
|
|
||
| useEffect(() => { | ||
| return () => { | ||
| __internal_WebAuthnAbortService.abort(); | ||
| }; | ||
| }, []); | ||
|
|
||
| return useCallback(async (...args: Parameters<typeof __experimental_authenticateWithPasskey>) => { | ||
| try { | ||
| const res = await __experimental_authenticateWithPasskey(...args); | ||
| switch (res.status) { | ||
| case 'complete': | ||
| return setActive({ session: res.createdSessionId, beforeEmit: navigateAfterSignIn }); | ||
| case 'needs_second_factor': | ||
| return navigate('../factor-two'); | ||
| default: | ||
| return console.error(clerkInvalidFAPIResponse(res.status, supportEmail)); | ||
| } | ||
| } catch (err) { | ||
| // In case of autofill, if retrieval of credentials is aborted just return to avoid updating state of unmounted components. | ||
| if (isClerkRuntimeError(err) && err.code === 'passkey_retrieval_aborted') { | ||
| return; | ||
| } | ||
| if (isUserLockedError(err)) { | ||
| // @ts-expect-error -- private method for the time being | ||
| return clerk.__internal_navigateWithError('..', err.errors[0]); | ||
| } | ||
| handleError(err, [], card.setError); | ||
| } | ||
| }, []); | ||
| } | ||
|
|
||
| export { useHandleAuthenticateWithPasskey }; |
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.
@desiprisg @anagstef Please let me know if we have new patterns that this code should align with.
In the designs this icon have a size of
48x48which is not covered by the current Icon implementation and just adding anxlvariant does not feel right as thelgrepresents a20x20so the difference would be quite large between them.We may add a new
Header.Iconcomponent, but as long as this is used in only one place do we need them 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.
Maybe the
Header.Iconwill make sense in order to have a proper descriptor instead of thepasskeyIcondescriptor. WDYT ?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.
It's ok to keep the width and height values.
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.
I'd say we don't add a
Header.Iconyet. Let's keep the Icon as is for now. :)