Skip to content

armgit / ente

Public Imported from GitHub
0

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

Outline

Manav Rathib7e601572060
diff --git a/web/packages/accounts/pages/change-password.tsx b/web/packages/accounts/pages/change-password.tsx
index aea4641c30..c05ed5f527 100644
--- a/web/packages/accounts/pages/change-password.tsx
+++ b/web/packages/accounts/pages/change-password.tsx
@@ -21,6 +21,8 @@ import { savedLocalUser } from "../services/accounts-db";
/**
* A page that allows a user to reset or change their password.
+ *
+ * See: [Note: Login pages]
*/
const Page: React.FC = () => {
const [user, setUser] = useState<LocalUser | undefined>(undefined);
diff --git a/web/packages/accounts/pages/credentials.tsx b/web/packages/accounts/pages/credentials.tsx
index 1d91bb89e5..f28bfceaaf 100644
--- a/web/packages/accounts/pages/credentials.tsx
+++ b/web/packages/accounts/pages/credentials.tsx
@@ -19,6 +19,7 @@ import {
getToken,
savedIsFirstLogin,
savedKeyAttributes,
+ savedPartialLocalUser,
savedSRPAttributes,
saveIsFirstLogin,
saveKeyAttributes,
@@ -79,15 +80,16 @@ import { useCallback, useEffect, useState } from "react";
const Page: React.FC = () => {
const { logout, showMiniDialog } = useBaseContext();
- const [srpAttributes, setSrpAttributes] = useState<SRPAttributes>();
+ const [user, setUser] = useState<PartialLocalUser | undefined>(undefined);
const [keyAttributes, setKeyAttributes] = useState<KeyAttributes>();
- const [user, setUser] = useState<PartialLocalUser>();
+ const [srpAttributes, setSrpAttributes] = useState<SRPAttributes>();
const [passkeyVerificationData, setPasskeyVerificationData] = useState<
{ passkeySessionID: string; url: string } | undefined
>();
const [sessionValidityCheck, setSessionValidityCheck] = useState<
Promise<void> | undefined
>();
+
const {
secondFactorChoiceProps,
userVerificationResultAfterResolvingSecondFactorChoice,
@@ -127,11 +129,12 @@ const Page: React.FC = () => {
useEffect(() => {
const main = async () => {
- const user: PartialLocalUser = getData("user");
+ const user = savedPartialLocalUser();
if (!user?.email) {
void router.push("/");
return;
}
+
setUser(user);
await updateSessionFromElectronSafeStorageIfNeeded();
if (await haveAuthenticatedSession()) {
diff --git a/web/packages/accounts/pages/generate.tsx b/web/packages/accounts/pages/generate.tsx
index 4e5d38ed1b..92d3bb1900 100644
--- a/web/packages/accounts/pages/generate.tsx
+++ b/web/packages/accounts/pages/generate.tsx
@@ -6,9 +6,9 @@ import {
} from "ente-accounts/components/layouts/centered-paper";
import { RecoveryKey } from "ente-accounts/components/RecoveryKey";
import {
- getData,
savedJustSignedUp,
savedOriginalKeyAttributes,
+ savedPartialLocalUser,
saveJustSignedUp,
} from "ente-accounts/services/accounts-db";
import { appHomeRoute } from "ente-accounts/services/redirect";
@@ -39,31 +39,35 @@ import {
type NewPasswordFormProps,
} from "../components/NewPasswordForm";
+/**
+ * A page that allows the user to generate key attributes if needed, and shows
+ * them their recovery key.
+ *
+ * See: [Note: Login pages]
+ */
const Page: React.FC = () => {
const { logout, showMiniDialog } = useBaseContext();
- const [user, setUser] = useState<PartialLocalUser>();
+ const [user, setUser] = useState<PartialLocalUser | undefined>(undefined);
const [openRecoveryKey, setOpenRecoveryKey] = useState(false);
- const [loading, setLoading] = useState(true);
const router = useRouter();
useEffect(() => {
- const user: PartialLocalUser = getData("user");
- setUser(user);
+ const user = savedPartialLocalUser();
if (!user?.token) {
void router.push("/");
} else if (haveCredentialsInSession()) {
if (savedJustSignedUp()) {
setOpenRecoveryKey(true);
- setLoading(false);
+ setUser(user);
} else {
void router.push(appHomeRoute);
}
} else if (savedOriginalKeyAttributes()?.encryptedKey) {
void router.push("/credentials");
} else {
- setLoading(false);
+ setUser(user);
}
}, [router]);
@@ -97,7 +101,7 @@ const Page: React.FC = () => {
return (
<>
- {loading || !user ? (
+ {!user ? (
<LoadingIndicator />
) : openRecoveryKey ? (
<RecoveryKey
@@ -109,7 +113,7 @@ const Page: React.FC = () => {
<AccountsPageContents>
<AccountsPageTitle>{t("set_password")}</AccountsPageTitle>
<NewPasswordForm
- userEmail={user.email! /* TODO(RE):*/}
+ userEmail={user.email!}
submitButtonTitle={t("set_password")}
onSubmit={handleSubmit}
/>
diff --git a/web/packages/accounts/pages/login.tsx b/web/packages/accounts/pages/login.tsx
index b57495a36d..bf754056ff 100644
--- a/web/packages/accounts/pages/login.tsx
+++ b/web/packages/accounts/pages/login.tsx
@@ -1,36 +1,109 @@
import { AccountsPageContents } from "ente-accounts/components/layouts/centered-paper";
import { LoginContents } from "ente-accounts/components/LoginContents";
-import { getData } from "ente-accounts/services/accounts-db";
+import { savedPartialLocalUser } from "ente-accounts/services/accounts-db";
import { LoadingIndicator } from "ente-base/components/loaders";
import { customAPIHost } from "ente-base/origins";
import { useRouter } from "next/router";
-import React, { useEffect, useState } from "react";
+import React, { useCallback, useEffect, useState } from "react";
/**
* A page that allows the user to login into their existing Ente account.
+ *
+ * [Note: Login pages]
+ *
+ * There are multiple pages that comprise the login flow, with redirects amongst
+ * themselves depending on various scenarios and partial login states.
+ *
+ * - "/signup" - A page that allows the user to signup for a new Ente account.
+ *
+ * - Redirects to "/login" if the user chooses the "already have an account"
+ * option.
+ *
+ * - Redirects to "/verify" if there is already an `email` present in the
+ * saved partial local user, or after obtaining the email.
+ *
+ * - "/login" - A page that allows the user to login into their existing Ente
+ * account.
+ *
+ * - Redirects to "/signup" if the user chooses the "create new account"
+ * option.
+ *
+ * - Redirects to "/verify" if there is already an `email` present in the
+ * saved partial local user, or after obtaining the email if the user's has
+ * enabled email verification for their account.
+ *
+ * - Redirects to "/credentials" after obtaining the email if the user has not
+ * enabled email verification for their account.
+ *
+ * - "/verify" - A page that allows the user to verify their email.
+ *
+ * - Redirects to "/" if there is no `email` present in the saved partial
+ * local user.
+ *
+ * - Redirects to "/credentials" if email verification is not needed, and also
+ * when email verification completes.
+ *
+ * - Redirects to "/two-factor/verify" once email verification is complete if
+ * the user has setup an additional TOTP second factor that also needs to be
+ * verified.
+ *
+ * - Redirects to the passkey app once email verification is complete if the
+ * user has setup an additional passkey that also needs to be verified.
+ *
+ * - "/credentials" - A page that allows the user to enter their password to
+ * authenticate (initial login) or reauthenticate (new web app tab)
+ *
+ * - Redirects to "/" if there is no `email` present in the saved partial
+ * local user.
+ *
+ * - "/generate" - A page that allows the user to generate key attributes if
+ * needed, and shows them their recovery key.
+ *
+ * - Redirects to "/" if there is no `email` present in the saved partial
+ * local user, or after viewing the recovery key, or after the user sets
+ * their password (if they did no have key attributes).
+ *
+ * - Redirects to "/credentials" if they already have the original key
+ * attributes.
+ *
+ * - "/recover" - A page that allows the user to recover their master key using
+ * their recovery key.
+ *
+ * - Redirects to "/" if there is no `email` present in the saved partial
+ * local user.
+ *
+ * - Redirects to "/verify" if there is no `encryptedToken` (or `token`)
+ * present in the saved partial local user.
+ *
+ * - Redirects to "/generate" if there are no saved key attributes.
+ *
+ * - Redirects to "/change-password" once the recovery key is verified.
+ *
+ * - "/change-password" - A page that allows the user to reset their password.
+ *
+ * - Redirects to "/" if there is no `email` present in the saved partial
+ * user, and after successfully changing the password.
+ *
*/
const Page: React.FC = () => {
const [loading, setLoading] = useState(true);
- const [host, setHost] = useState<string | undefined>();
+ const [host, setHost] = useState<string | undefined>(undefined);
const router = useRouter();
useEffect(() => {
void customAPIHost().then(setHost);
- const user = getData("user");
- if (user?.email) {
- void router.push("/verify");
- }
+ if (savedPartialLocalUser()?.email) void router.push("/verify");
setLoading(false);
}, [router]);
- const onSignUp = () => void router.push("/signup");
+ const onSignUp = useCallback(() => void router.push("/signup"), [router]);
return loading ? (
<LoadingIndicator />
) : (
<AccountsPageContents>
- <LoginContents {...{ onSignUp, host }} />
+ <LoginContents {...{ host, onSignUp }} />
</AccountsPageContents>
);
};
diff --git a/web/packages/accounts/pages/recover.tsx b/web/packages/accounts/pages/recover.tsx
index 65e9b71e10..ac91d3c9fc 100644
--- a/web/packages/accounts/pages/recover.tsx
+++ b/web/packages/accounts/pages/recover.tsx
@@ -4,15 +4,12 @@ import {
AccountsPageTitle,
} from "ente-accounts/components/layouts/centered-paper";
import {
- getData,
savedKeyAttributes,
+ savedPartialLocalUser,
} from "ente-accounts/services/accounts-db";
import { recoveryKeyFromMnemonic } from "ente-accounts/services/recovery-key";
import { appHomeRoute, stashRedirect } from "ente-accounts/services/redirect";
-import type {
- KeyAttributes,
- PartialLocalUser,
-} from "ente-accounts/services/user";
+import type { KeyAttributes } from "ente-accounts/services/user";
import { sendOTT } from "ente-accounts/services/user";
import { decryptAndStoreToken } from "ente-accounts/utils/helpers";
import { LinkButton } from "ente-base/components/LinkButton";
@@ -31,6 +28,12 @@ import { t } from "i18next";
import { useRouter } from "next/router";
import { useEffect, useState } from "react";
+/**
+ * A page that allows the user to enter their recovery key to recover their
+ * master key if they've forgotten their password.
+ *
+ * See: [Note: Login pages]
+ */
const Page: React.FC = () => {
const { showMiniDialog } = useBaseContext();
@@ -41,7 +44,7 @@ const Page: React.FC = () => {
const router = useRouter();
useEffect(() => {
- const user: PartialLocalUser = getData("user");
+ const user = savedPartialLocalUser();
if (!user?.email) {
void router.push("/");
return;
diff --git a/web/packages/accounts/pages/signup.tsx b/web/packages/accounts/pages/signup.tsx
index ed72e76795..cff9575c76 100644
--- a/web/packages/accounts/pages/signup.tsx
+++ b/web/packages/accounts/pages/signup.tsx
@@ -8,6 +8,8 @@ import React, { useCallback, useEffect, useState } from "react";
/**
* A page that allows the user to signup for a new Ente account.
+ *
+ * See: [Note: Login pages]
*/
const Page: React.FC = () => {
const [loading, setLoading] = useState(true);
diff --git a/web/packages/accounts/pages/verify.tsx b/web/packages/accounts/pages/verify.tsx
index b111bf5bfa..7111b57435 100644
--- a/web/packages/accounts/pages/verify.tsx
+++ b/web/packages/accounts/pages/verify.tsx
@@ -51,6 +51,8 @@ import { Trans } from "react-i18next";
/**
* A page that allows the user to verify their email.
+ *
+ * See: [Note: Login pages]
*/
const Page: React.FC = () => {
const { logout, showMiniDialog } = useBaseContext();
@@ -228,13 +230,13 @@ const Page: React.FC = () => {
/>
<AccountsPageFooter>
- {resend === 0 && (
+ {resend == 0 && (
<LinkButton onClick={resendEmail}>
{t("resend_code")}
</LinkButton>
)}
- {resend === 1 && <span>{t("status_sending")}</span>}
- {resend === 2 && <span>{t("status_sent")}</span>}
+ {resend == 1 && <span>{t("status_sending")}</span>}
+ {resend == 2 && <span>{t("status_sent")}</span>}
<LinkButton onClick={logout}>{t("change_email")}</LinkButton>
</AccountsPageFooter>