π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Remove alert
Manav Rathi7b45d689db24
diff --git a/web/apps/accounts/src/pages/passkeys/verify.tsx b/web/apps/accounts/src/pages/passkeys/verify.tsxindex c3e56194bd..1fb3eeda2d 100644--- a/web/apps/accounts/src/pages/passkeys/verify.tsx+++ b/web/apps/accounts/src/pages/passkeys/verify.tsx@@ -15,6 +15,7 @@ import { useEffect, useState } from "react";import {beginPasskeyAuthentication,finishPasskeyAuthentication,+ isWebAuthnSupported,isWhitelistedRedirect,type BeginPasskeyAuthenticationResponse,} from "services/passkey";@@ -27,14 +28,20 @@ const Page = () => {* To avoid confusion with useState, we call it status instead. */type Status =| "loading" /* Can happen multiple times in the flow */+ | "webAuthnNotSupported" /* Unrecoverable error */| "unknownRedirect" /* Unrecoverable error */- | "failed" /* Generic error */+ | "failed" /* Recoverable error */| "waitingForUser"; /* ...to authenticate with their passkey */const [status, setStatus] = useState<Status>("loading");/** (re)start the authentication flow */const authenticate = async () => {+ if (!isWebAuthnSupported()) {+ setStatus("webAuthnNotSupported");+ return;+ }+const searchParams = new URLSearchParams(window.location.search);// Extract redirect from the query params.@@ -104,9 +111,6 @@ const Page = () => {}if (!credential) {- if (!isWebAuthnSupported()) {- alert("WebAuthn is not supported in this browser");- }setStatus("failed");return;}@@ -141,13 +145,6 @@ const Page = () => {return data;};- function isWebAuthnSupported(): boolean {- if (!navigator.credentials) {- return false;- }- return true;- }-const getCredential = async (publicKey: any,timeoutMillis: number = 60000, // Default timeout of 60 seconds@@ -193,6 +190,7 @@ const Page = () => {const components: Record<Status, React.ReactNode> = {loading: <Loading />,+ webAuthnNotSupported: <WebAuthnNotSupported />,unknownRedirect: <UnknownRedirect />,failed: <RetriableFailed onRetry={handleRetry} />,waitingForUser: <WaitingForUser />,@@ -215,6 +213,11 @@ const UnknownRedirect: React.FC = () => {return <Failed message={t("PASSKEY_LOGIN_URL_INVALID")} />;};+const WebAuthnNotSupported: React.FC = () => {+ // TODO-PK(MR): Translate+ return <Failed message={"Passkeys are not supported in this browser"} />;+};+interface FailedProps {message: string;}diff --git a/web/apps/accounts/src/services/passkey.ts b/web/apps/accounts/src/services/passkey.tsindex 093c1ec8d6..c9235d0ef9 100644--- a/web/apps/accounts/src/services/passkey.ts+++ b/web/apps/accounts/src/services/passkey.ts@@ -13,6 +13,9 @@ import { z } from "zod";const ENDPOINT = getEndpoint();+/** Return true if the user's browser supports WebAuthn (Passkeys). */+export const isWebAuthnSupported = () => !!navigator.credentials;+/*** Variant of {@link authenticatedRequestHeaders} but for authenticated requests* made by the accounts app.