π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Inline
Manav Rathi4442b3af2889
diff --git a/web/packages/accounts/components/two-factor/TwoFactorSetup.tsx b/web/packages/accounts/components/two-factor/TwoFactorSetup.tsxdeleted file mode 100644index 1732cf57d7..0000000000--- a/web/packages/accounts/components/two-factor/TwoFactorSetup.tsx+++ /dev/null@@ -1,105 +0,0 @@-import { CodeBlock } from "@/accounts/components/CodeBlock";-import { LinkButton } from "@/base/components/LinkButton";-import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";-import { VerticallyCentered } from "@ente/shared/components/Container";-import { Stack, styled, Typography } from "@mui/material";-import { t } from "i18next";-import { useState } from "react";-import { type SetupMode } from "../../pages/two-factor/setup";-import type { TwoFactorSecret } from "../../services/user";--interface TwoFactorSetupProps {- twoFactorSecret?: TwoFactorSecret;-}--export function TwoFactorSetup({ twoFactorSecret }: TwoFactorSetupProps) {- const [setupMode, setSetupMode] = useState<SetupMode>("qrCode");-- const changeToManualMode = () => setSetupMode("manualCode");-- const changeToQRMode = () => setSetupMode("qrCode");-- return (- <VerticallyCentered sx={{ mb: 3, gap: 1 }}>- {setupMode == "qrCode" ? (- <SetupQRMode- twoFactorSecret={twoFactorSecret}- changeToManualMode={changeToManualMode}- />- ) : (- <SetupManualMode- twoFactorSecret={twoFactorSecret}- changeToQRMode={changeToQRMode}- />- )}- </VerticallyCentered>- );-}--interface SetupManualModeProps {- twoFactorSecret?: TwoFactorSecret;- changeToQRMode: () => void;-}-function SetupManualMode({- twoFactorSecret,- changeToQRMode,-}: SetupManualModeProps) {- return (- <Stack sx={{ gap: 3 }}>- <Typography sx={{ color: "text.muted" }}>- {t("two_factor_manual_entry_message")}- </Typography>- <CodeBlock code={twoFactorSecret?.secretCode} />- <LinkButton onClick={changeToQRMode}>- {t("scan_qr_title")}- </LinkButton>- </Stack>- );-}--interface SetupQRModeProps {- twoFactorSecret?: TwoFactorSecret;- changeToManualMode: () => void;-}--function SetupQRMode({- twoFactorSecret,- changeToManualMode,-}: SetupQRModeProps) {- return (- <>- <Typography sx={{ color: "text.muted" }}>- {t("two_factor_qr_help")}- </Typography>- {!twoFactorSecret ? (- <LoadingQRCode>- <ActivityIndicator />- </LoadingQRCode>- ) : (- <QRCode- src={`data:image/png;base64,${twoFactorSecret?.qrCode}`}- />- )}- <LinkButton onClick={changeToManualMode}>- {t("two_factor_manual_entry_title")}- </LinkButton>- </>- );-}--const QRCode = styled("img")(- ({ theme }) => `- height: 200px;- width: 200px;- margin: ${theme.spacing(2)};-`,-);--const LoadingQRCode = styled(VerticallyCentered)(- ({ theme }) => `- width: 200px;- aspect-ratio:1;- border: 1px solid ${theme.vars.palette.stroke.muted};- margin: ${theme.spacing(2)};- `,-);diff --git a/web/packages/accounts/pages/two-factor/setup.tsx b/web/packages/accounts/pages/two-factor/setup.tsxindex 168b75826f..448f4e74ff 100644--- a/web/packages/accounts/pages/two-factor/setup.tsx+++ b/web/packages/accounts/pages/two-factor/setup.tsx@@ -1,10 +1,13 @@-import { TwoFactorSetup } from "@/accounts/components/two-factor/TwoFactorSetup";+import { CodeBlock } from "@/accounts/components/CodeBlock";import { Verify2FACodeForm } from "@/accounts/components/Verify2FACodeForm";import { appHomeRoute } from "@/accounts/services/redirect";import type { TwoFactorSecret } from "@/accounts/services/user";import { enableTwoFactor, setupTwoFactor } from "@/accounts/services/user";import { CenteredFill } from "@/base/components/containers";+import { LinkButton } from "@/base/components/LinkButton";+import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";import { FocusVisibleButton } from "@/base/components/mui/FocusVisibleButton";+import { VerticallyCentered } from "@ente/shared/components/Container";import { encryptWithRecoveryKey } from "@ente/shared/crypto/helpers";import { getData, LS_KEYS, setLSUser } from "@ente/shared/storage/localStorage";import { Paper, Stack, styled, Typography } from "@mui/material";@@ -12,8 +15,6 @@ import { t } from "i18next";import { useRouter } from "next/router";import React, { useCallback, useEffect, useState } from "react";-export type SetupMode = "qrCode" | "manualCode";-const Page: React.FC = () => {const [twoFactorSecret, setTwoFactorSecret] = useState<TwoFactorSecret | undefined@@ -48,21 +49,19 @@ const Page: React.FC = () => {<Typography variant="h5" sx={{ textAlign: "center" }}>{t("two_factor")}</Typography>- <Stack>- <TwoFactorSetup twoFactorSecret={twoFactorSecret} />- <Verify2FACodeForm- onSubmit={handleSubmit}- onSuccess={handleSuccess}- submitButtonText={t("enable")}- />- <Stack sx={{ alignItems: "center" }}>- <FocusVisibleButton- variant="text"- onClick={router.back}- >- {t("go_back")}- </FocusVisibleButton>- </Stack>+ <Instructions twoFactorSecret={twoFactorSecret} />+ <Verify2FACodeForm+ onSubmit={handleSubmit}+ onSuccess={handleSuccess}+ submitButtonText={t("enable")}+ />+ <Stack sx={{ alignItems: "center" }}>+ <FocusVisibleButton+ variant="text"+ onClick={router.back}+ >+ {t("go_back")}+ </FocusVisibleButton></Stack></ContentsPaper></CenteredFill>@@ -81,3 +80,88 @@ const ContentsPaper = styled(Paper)(({ theme }) => ({flexDirection: "column",gap: theme.spacing(4),}));++interface InstructionsProps {+ twoFactorSecret: TwoFactorSecret | undefined;+}++const Instructions: React.FC<InstructionsProps> = ({ twoFactorSecret }) => {+ const [setupMode, setSetupMode] = useState<"qr" | "manual">("qr");++ return (+ <VerticallyCentered sx={{ mb: 3, gap: 1 }}>+ {setupMode == "qr" ? (+ <SetupQRMode+ twoFactorSecret={twoFactorSecret}+ onChangeMode={() => setSetupMode("manual")}+ />+ ) : (+ <SetupManualMode+ twoFactorSecret={twoFactorSecret}+ onChangeMode={() => setSetupMode("qr")}+ />+ )}+ </VerticallyCentered>+ );+};++interface SetupManualModeProps {+ twoFactorSecret: TwoFactorSecret | undefined;+ onChangeMode: () => void;+}++const SetupManualMode: React.FC<SetupManualModeProps> = ({+ twoFactorSecret,+ onChangeMode,+}) => (+ <Stack sx={{ gap: 3 }}>+ <Typography sx={{ color: "text.muted" }}>+ {t("two_factor_manual_entry_message")}+ </Typography>+ <CodeBlock code={twoFactorSecret?.secretCode} />+ <LinkButton onClick={onChangeMode}>{t("scan_qr_title")}</LinkButton>+ </Stack>+);++interface SetupQRModeProps {+ twoFactorSecret?: TwoFactorSecret;+ onChangeMode: () => void;+}++const SetupQRMode: React.FC<SetupQRModeProps> = ({+ twoFactorSecret,+ onChangeMode,+}) => (+ <>+ <Typography sx={{ color: "text.muted" }}>+ {t("two_factor_qr_help")}+ </Typography>+ {!twoFactorSecret ? (+ <LoadingQRCode>+ <ActivityIndicator />+ </LoadingQRCode>+ ) : (+ <QRCode src={`data:image/png;base64,${twoFactorSecret?.qrCode}`} />+ )}+ <LinkButton onClick={onChangeMode}>+ {t("two_factor_manual_entry_title")}+ </LinkButton>+ </>+);++const QRCode = styled("img")(+ ({ theme }) => `+ height: 200px;+ width: 200px;+ margin: ${theme.spacing(2)};+`,+);++const LoadingQRCode = styled(VerticallyCentered)(+ ({ theme }) => `+ width: 200px;+ aspect-ratio:1;+ border: 1px solid ${theme.vars.palette.stroke.muted};+ margin: ${theme.spacing(2)};+ `,+);