-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WebApp] Add passkey support logic (#1162)
- Loading branch information
Showing
6 changed files
with
88 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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 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
26 changes: 26 additions & 0 deletions
26
packages/web-app/src/modules/passkey-setup/PasskeyStore.tsx
This file contains 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,26 @@ | ||
import { action, observable, runInAction } from 'mobx' | ||
import { getIsPasskeySupported } from './utils' | ||
|
||
export class PasskeyStore { | ||
@observable | ||
public isPasskeySupported: boolean = false | ||
|
||
constructor() { | ||
this.setIsPasskeySupported() | ||
} | ||
|
||
@action | ||
private async setIsPasskeySupported(): Promise<void> { | ||
try { | ||
const isPasskeySupported = await getIsPasskeySupported() | ||
runInAction(() => { | ||
this.isPasskeySupported = isPasskeySupported | ||
}) | ||
} catch (error) { | ||
console.error('Error checking passkey support:', error) | ||
runInAction(() => { | ||
this.isPasskeySupported = false | ||
}) | ||
} | ||
} | ||
} |
This file contains 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 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './PasskeySetupPageContainer' | ||
export * from './PasskeyStore' |
This file contains 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,25 @@ | ||
export const getIsPasskeySupported = async (): Promise<boolean> => { | ||
// Availability of `window.PublicKeyCredential` means WebAuthn is usable. | ||
// `isUserVerifyingPlatformAuthenticatorAvailable` means the feature detection is usable. | ||
// `isConditionalMediationAvailable` means the feature detection is usable. | ||
if ( | ||
window.PublicKeyCredential && | ||
typeof PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable === 'function' && | ||
typeof PublicKeyCredential.isConditionalMediationAvailable === 'function' | ||
) { | ||
try { | ||
const [isAuthenticatorAvailable, isMediationAvailable] = await Promise.all([ | ||
PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable(), | ||
PublicKeyCredential.isConditionalMediationAvailable(), | ||
]) | ||
|
||
return isAuthenticatorAvailable && isMediationAvailable | ||
} catch (error) { | ||
console.error('Error checking passkey support:', error) | ||
return false | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|