Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

update(photos):update-passkey-verify-page-layout

Aswin Asok37c54b34300e
diff --git a/web/apps/photos/src/components/PhotosAuthShell.tsx b/web/apps/photos/src/components/PhotosAuthShell.tsx
index 8600661f8b..9c5621ab3a 100644
--- a/web/apps/photos/src/components/PhotosAuthShell.tsx
+++ b/web/apps/photos/src/components/PhotosAuthShell.tsx
@@ -8,6 +8,7 @@ import {
authAboveMobileMediaQuery,
authColorVariables,
authDisplayFontFamily,
+ authMobileMediaQuery,
} from "./auth/styles";
interface PhotosAuthShellProps extends React.PropsWithChildren {
@@ -222,6 +223,7 @@ const ContentColumn = styled("div", {
display: "flex",
flexDirection: "column",
gap: "24px",
+ [authMobileMediaQuery]: { flexGrow: 1 },
[authAboveMobileMediaQuery]: {
width: "440px",
maxWidth: "100%",
diff --git a/web/apps/photos/src/components/auth/PasskeyVerificationForm.tsx b/web/apps/photos/src/components/auth/PasskeyVerificationForm.tsx
new file mode 100644
index 0000000000..3b45561bd8
--- /dev/null
+++ b/web/apps/photos/src/components/auth/PasskeyVerificationForm.tsx
@@ -0,0 +1,188 @@
+import { InformationCircleIcon } from "@hugeicons/core-free-icons";
+import { HugeiconsIcon } from "@hugeicons/react";
+import { CircularProgress, styled } from "@mui/material";
+import type { VerifyingPasskeyPresentationProps } from "ente-accounts/components/LoginComponents";
+import { pt } from "ente-base/i18n";
+import { t } from "i18next";
+import type React from "react";
+import { Button } from "./Button";
+import { FormFooter } from "./FormFooter";
+import { ScreenHeader } from "./ScreenHeader";
+import {
+ authBodyTypography,
+ authMiniTypography,
+ authTransientProps,
+} from "./styles";
+import { TextLink } from "./TextLink";
+
+export function PasskeyVerificationForm({
+ email,
+ host,
+ verificationStatus,
+ isChecking,
+ onRetry,
+ onCheckStatus,
+ onRecover,
+ onChangeEmail,
+}: VerifyingPasskeyPresentationProps): React.JSX.Element {
+ const stalled = verificationStatus === "pending";
+
+ const checkStatusButton = (
+ <Button
+ fullWidth
+ variant={stalled ? "secondary" : "primary"}
+ onClick={onCheckStatus}
+ loading={isChecking}
+ >
+ {t("check_status")}
+ </Button>
+ );
+
+ const reopenButton = (
+ <Button
+ fullWidth
+ variant={stalled ? "primary" : "secondary"}
+ onClick={onRetry}
+ disabled={isChecking}
+ >
+ {pt("Open the browser window again")}
+ </Button>
+ );
+
+ return (
+ <>
+ <ScreenHeader
+ title={pt("Verify your passkey")}
+ subtitle={
+ <>
+ {pt("We opened a browser window")}
+ {email ? (
+ <>
+ {pt(" for ")}
+ <Email>{email}</Email>
+ </>
+ ) : null}
+ </>
+ }
+ />
+ <StatusCard role="status" $stalled={stalled}>
+ {stalled ? (
+ <StatusIcon>
+ <HugeiconsIcon
+ icon={InformationCircleIcon}
+ size={20}
+ strokeWidth={2}
+ aria-hidden="true"
+ />
+ </StatusIcon>
+ ) : (
+ <CircularProgress
+ size={20}
+ sx={{
+ color: "var(--photos-auth-primary)",
+ flexShrink: 0,
+ }}
+ />
+ )}
+ <StatusText>
+ <StatusTitle>
+ {stalled
+ ? pt("Still waiting")
+ : t("waiting_for_verification")}
+ </StatusTitle>
+ <StatusCaption>
+ {stalled
+ ? pt(
+ "The browser window may have been closed before you finished. Open it again to retry.",
+ )
+ : pt("This page updates on its own")}
+ </StatusCaption>
+ </StatusText>
+ </StatusCard>
+ <FormFooter>
+ {stalled ? (
+ <>
+ {reopenButton}
+ {checkStatusButton}
+ </>
+ ) : (
+ <>
+ {checkStatusButton}
+ {reopenButton}
+ </>
+ )}
+ <FooterLinks>
+ <TextLink onClick={onRecover} disabled={isChecking}>
+ {t("recover_account")}
+ </TextLink>
+ <TextLink onClick={onChangeEmail} disabled={isChecking}>
+ {t("change_email")}
+ </TextLink>
+ </FooterLinks>
+ <Host>{host ?? ""}</Host>
+ </FormFooter>
+ </>
+ );
+}
+
+const Email = styled("strong")({
+ color: "var(--photos-auth-text)",
+ wordBreak: "break-word",
+});
+
+const StatusCard = styled(
+ "div",
+ authTransientProps,
+)<{ $stalled: boolean }>(({ $stalled }) => ({
+ padding: "16px",
+ borderRadius: "20px",
+ display: "flex",
+ alignItems: $stalled ? "flex-start" : "center",
+ gap: "12px",
+ backgroundColor: $stalled
+ ? "color-mix(in srgb, var(--photos-auth-caution) 12%, transparent)"
+ : "var(--photos-auth-field)",
+ boxShadow: `inset 0 0 0 1px ${
+ $stalled
+ ? "color-mix(in srgb, var(--photos-auth-caution) 32%, transparent)"
+ : "var(--photos-auth-stroke)"
+ }`,
+}));
+
+const StatusIcon = styled("div")({
+ flexShrink: 0,
+ display: "flex",
+ color: "var(--photos-auth-caution)",
+});
+
+const StatusText = styled("div")({
+ display: "flex",
+ flexDirection: "column",
+ gap: "2px",
+});
+
+const StatusTitle = styled("div")({
+ ...authBodyTypography,
+ fontWeight: 600,
+ color: "var(--photos-auth-text)",
+});
+
+const StatusCaption = styled("p")({
+ ...authMiniTypography,
+ margin: 0,
+ textWrap: "pretty",
+ color: "var(--photos-auth-text-muted)",
+});
+
+const FooterLinks = styled("div")({
+ display: "flex",
+ justifyContent: "space-between",
+ gap: "16px",
+});
+
+const Host = styled("div")({
+ ...authMiniTypography,
+ minHeight: "16px",
+ textAlign: "center",
+ color: "var(--photos-auth-text-faint)",
+});
diff --git a/web/apps/photos/src/pages/credentials.tsx b/web/apps/photos/src/pages/credentials.tsx
index 9b8df2e13d..d087f6ab10 100644
--- a/web/apps/photos/src/pages/credentials.tsx
+++ b/web/apps/photos/src/pages/credentials.tsx
@@ -1 +1,28 @@
-export { default } from "ente-accounts/pages/credentials";
+import { PasskeyVerificationForm } from "@/components/auth/PasskeyVerificationForm";
+import { PhotosAuthShell } from "@/components/PhotosAuthShell";
+import { featureFlags } from "@/featureFlags";
+import type { VerifyingPasskeyPresentationProps } from "ente-accounts/components/LoginComponents";
+import AccountsCredentialsPage from "ente-accounts/pages/credentials";
+import type React from "react";
+
+function PasskeyPresentation(
+ props: VerifyingPasskeyPresentationProps,
+): React.JSX.Element {
+ return (
+ <PhotosAuthShell>
+ <PasskeyVerificationForm {...props} />
+ </PhotosAuthShell>
+ );
+}
+
+function CredentialsPage(): React.JSX.Element {
+ if (!featureFlags.enableNewPhotosAuthFlow) {
+ return <AccountsCredentialsPage />;
+ }
+
+ return (
+ <AccountsCredentialsPage passkeyPresentation={PasskeyPresentation} />
+ );
+}
+
+export default CredentialsPage;
diff --git a/web/apps/photos/src/pages/verify.tsx b/web/apps/photos/src/pages/verify.tsx
index f9776f120b..70494e2c0e 100644
--- a/web/apps/photos/src/pages/verify.tsx
+++ b/web/apps/photos/src/pages/verify.tsx
@@ -1,6 +1,8 @@
+import { PasskeyVerificationForm } from "@/components/auth/PasskeyVerificationForm";
import { VerifyEmailForm } from "@/components/auth/VerifyEmailForm";
import { PhotosAuthShell } from "@/components/PhotosAuthShell";
import { featureFlags } from "@/featureFlags";
+import type { VerifyingPasskeyPresentationProps } from "ente-accounts/components/LoginComponents";
import AccountsVerifyPage, {
type VerifyEmailPresentationProps,
} from "ente-accounts/pages/verify";
@@ -16,12 +18,27 @@ function VerifyEmailPresentation(
);
}
+function PasskeyPresentation(
+ props: VerifyingPasskeyPresentationProps,
+): React.JSX.Element {
+ return (
+ <PhotosAuthShell>
+ <PasskeyVerificationForm {...props} />
+ </PhotosAuthShell>
+ );
+}
+
function VerifyPage(): React.JSX.Element {
if (!featureFlags.enableNewPhotosAuthFlow) {
return <AccountsVerifyPage />;
}
- return <AccountsVerifyPage presentation={VerifyEmailPresentation} />;
+ return (
+ <AccountsVerifyPage
+ presentation={VerifyEmailPresentation}
+ passkeyPresentation={PasskeyPresentation}
+ />
+ );
}
export default VerifyPage;
diff --git a/web/packages/accounts/components/LoginComponents.tsx b/web/packages/accounts/components/LoginComponents.tsx
index e432ceac63..653d2bbf96 100644
--- a/web/packages/accounts/components/LoginComponents.tsx
+++ b/web/packages/accounts/components/LoginComponents.tsx
@@ -77,12 +77,26 @@ export const AccountsPageFooterWithHost: React.FC<React.PropsWithChildren> = ({
);
};
+export type PasskeyVerificationStatus = "waiting" | "checking" | "pending";
+
+export interface VerifyingPasskeyPresentationProps {
+ email: string | undefined;
+ host: string | undefined;
+ verificationStatus: PasskeyVerificationStatus;
+ isChecking: boolean;
+ onRetry: () => void;
+ onCheckStatus: () => void;
+ onRecover: () => void;
+ onChangeEmail: () => void;
+}
+
interface VerifyingPasskeyProps {
passkeySessionID: string;
email: string | undefined;
onRetry: () => void;
logout: () => void;
showMiniDialog: (attrs: MiniDialogAttributes) => void;
+ presentation?: React.ComponentType<VerifyingPasskeyPresentationProps>;
}
export const VerifyingPasskey: React.FC<VerifyingPasskeyProps> = ({
@@ -91,13 +105,18 @@ export const VerifyingPasskey: React.FC<VerifyingPasskeyProps> = ({
onRetry,
logout,
showMiniDialog,
+ presentation: Presentation,
}) => {
- type VerificationStatus = "waiting" | "checking" | "pending";
const [verificationStatus, setVerificationStatus] =
- useState<VerificationStatus>("waiting");
+ useState<PasskeyVerificationStatus>("waiting");
+ const [host, setHost] = useState<string | undefined>();
const router = useRouter();
+ useEffect(() => {
+ if (Presentation) void customAPIHost().then(setHost);
+ }, [Presentation]);
+
const handleRetry = () => {
setVerificationStatus("waiting");
onRetry();
@@ -126,6 +145,25 @@ export const VerifyingPasskey: React.FC<VerifyingPasskeyProps> = ({
void router.push("/passkeys/recover");
};
+ const handleCheckStatusClick = () => {
+ void handleCheckStatus();
+ };
+
+ if (Presentation) {
+ return (
+ <Presentation
+ email={email}
+ host={host}
+ verificationStatus={verificationStatus}
+ isChecking={verificationStatus === "checking"}
+ onRetry={handleRetry}
+ onCheckStatus={handleCheckStatusClick}
+ onRecover={handleRecover}
+ onChangeEmail={logout}
+ />
+ );
+ }
+
return (
<AccountsPageContents>
<PasskeyHeader caption={email} />
diff --git a/web/packages/accounts/pages/credentials.tsx b/web/packages/accounts/pages/credentials.tsx
index 5f3c692678..5656239d79 100644
--- a/web/packages/accounts/pages/credentials.tsx
+++ b/web/packages/accounts/pages/credentials.tsx
@@ -3,6 +3,7 @@ import {
AccountsPageFooterWithHost,
PasswordHeader,
VerifyingPasskey,
+ type VerifyingPasskeyPresentationProps,
} from "ente-accounts/components/LoginComponents";
import { SecondFactorChoice } from "ente-accounts/components/SecondFactorChoice";
import { sessionExpiredDialogAttributes } from "ente-accounts/components/utils/dialog";
@@ -61,9 +62,13 @@ import log from "ente-base/log";
import { saveAuthToken, savedAuthToken } from "ente-base/token";
import { t } from "i18next";
import { useRouter } from "next/router";
-import { useCallback, useEffect, useState } from "react";
+import { useCallback, useEffect, useState, type ComponentType } from "react";
-const Page: React.FC = () => {
+export interface CredentialsPageProps {
+ passkeyPresentation?: ComponentType<VerifyingPasskeyPresentationProps>;
+}
+
+const Page: React.FC<CredentialsPageProps> = ({ passkeyPresentation }) => {
const { logout, showMiniDialog } = useBaseContext();
const [userEmail, setUserEmail] = useState<string>("");
@@ -294,6 +299,12 @@ const Page: React.FC = () => {
[postVerification, userEmail, sessionValidityCheck],
);
+ const handlePasskeyRetry = useCallback(() => {
+ if (passkeyVerificationData) {
+ openPasskeyVerificationURL(passkeyVerificationData);
+ }
+ }, [passkeyVerificationData]);
+
if (!userEmail) {
return <LoadingIndicator />;
}
@@ -315,9 +326,8 @@ const Page: React.FC = () => {
<VerifyingPasskey
email={userEmail}
passkeySessionID={passkeyVerificationData.passkeySessionID}
- onRetry={() =>
- openPasskeyVerificationURL(passkeyVerificationData)
- }
+ onRetry={handlePasskeyRetry}
+ presentation={passkeyPresentation}
{...{ logout, showMiniDialog }}
/>
);
diff --git a/web/packages/accounts/pages/verify.tsx b/web/packages/accounts/pages/verify.tsx
index 1255fa9ded..408b5ef628 100644
--- a/web/packages/accounts/pages/verify.tsx
+++ b/web/packages/accounts/pages/verify.tsx
@@ -4,7 +4,10 @@ import {
AccountsPageFooter,
AccountsPageTitle,
} from "ente-accounts/components/layouts/centered-paper";
-import { VerifyingPasskey } from "ente-accounts/components/LoginComponents";
+import {
+ VerifyingPasskey,
+ type VerifyingPasskeyPresentationProps,
+} from "ente-accounts/components/LoginComponents";
import { SecondFactorChoice } from "ente-accounts/components/SecondFactorChoice";
import { useSecondFactorChoiceIfNeeded } from "ente-accounts/components/utils/second-factor-choice";
import {
@@ -64,9 +67,13 @@ export interface VerifyEmailPresentationProps {
export interface VerifyPageProps {
presentation?: ComponentType<VerifyEmailPresentationProps>;
+ passkeyPresentation?: ComponentType<VerifyingPasskeyPresentationProps>;
}
-const Page: React.FC<VerifyPageProps> = ({ presentation: Presentation }) => {
+const Page: React.FC<VerifyPageProps> = ({
+ presentation: Presentation,
+ passkeyPresentation,
+}) => {
const { logout, showMiniDialog } = useBaseContext();
const [email, setEmail] = useState("");
@@ -172,6 +179,12 @@ const Page: React.FC<VerifyPageProps> = ({ presentation: Presentation }) => {
setTimeout(() => setResend("enable"), 3000);
}, [email]);
+ const handlePasskeyRetry = useCallback(() => {
+ if (passkeyVerificationData) {
+ openPasskeyVerificationURL(passkeyVerificationData);
+ }
+ }, [passkeyVerificationData]);
+
if (!email) {
return <LoadingIndicator />;
}
@@ -189,9 +202,8 @@ const Page: React.FC<VerifyPageProps> = ({ presentation: Presentation }) => {
<VerifyingPasskey
email={email}
passkeySessionID={passkeyVerificationData.passkeySessionID}
- onRetry={() =>
- openPasskeyVerificationURL(passkeyVerificationData)
- }
+ onRetry={handlePasskeyRetry}
+ presentation={passkeyPresentation}
{...{ logout, showMiniDialog }}
/>
);