Skip to content

armgit / ente

Public Imported from GitHub
0

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

Name shared account errors

Manav Rathi5609ddfcc426
diff --git a/web/apps/space/src/pages/passkeys/verify.tsx b/web/apps/space/src/pages/passkeys/verify.tsx
index 5a56916525..d02ea0381b 100644
--- a/web/apps/space/src/pages/passkeys/verify.tsx
+++ b/web/apps/space/src/pages/passkeys/verify.tsx
@@ -12,7 +12,6 @@ import {
import { spaceAuthErrorMessage } from "services/spaceAuthError";
import {
checkSpaceLoginPasskeyStatus,
- spaceLoginPasskeySessionExpiredErrorMessage,
useSpaceLoginTwoFactorInstead,
} from "services/spaceLogin";
import {
@@ -27,19 +26,6 @@ import { routeAfterCompletedLogin } from "utils/spaceLoginNavigation";
import { spaceRoutes } from "utils/spaceRoutes";
import { useSpaceRouter } from "utils/spaceRouteTransitions";
-const passkeyErrorMessage = (error: unknown) => {
- if (
- error instanceof Error &&
- error.message == spaceLoginPasskeySessionExpiredErrorMessage
- ) {
- return "Passkey session expired. Please sign in again.";
- }
- return spaceAuthErrorMessage(
- error,
- "Couldn't check passkey status. Please try again.",
- );
-};
-
const Page: React.FC = () => {
const router = useSpaceRouter();
const {
@@ -145,4 +131,10 @@ const Page: React.FC = () => {
);
};
+const passkeyErrorMessage = (error: unknown) =>
+ spaceAuthErrorMessage(
+ error,
+ "Couldn't check passkey status. Please try again.",
+ );
+
export default Page;
diff --git a/web/apps/space/src/services/spaceAuthError.ts b/web/apps/space/src/services/spaceAuthError.ts
index be8538b940..e90d8f3364 100644
--- a/web/apps/space/src/services/spaceAuthError.ts
+++ b/web/apps/space/src/services/spaceAuthError.ts
@@ -5,6 +5,7 @@ const spaceAuthErrorMessages = {
incorrect_credentials: "Incorrect email or password.",
insufficient_memory: "This device doesn't have enough memory to continue.",
login_session_expired: "Login session expired. Please sign in again.",
+ passkey_session_expired: "Passkey session expired. Please sign in again.",
signup_incomplete:
"Account setup incomplete. Create account to finish setup.",
signup_session_expired: "Signup session expired. Please sign in.",
diff --git a/web/apps/space/src/services/spaceLogin.ts b/web/apps/space/src/services/spaceLogin.ts
index ef7564b464..3233fbbf8a 100644
--- a/web/apps/space/src/services/spaceLogin.ts
+++ b/web/apps/space/src/services/spaceLogin.ts
@@ -16,7 +16,6 @@ import {
import {
checkPasskeyVerificationStatus,
clearInflightPasskeySessionID,
- passkeySessionExpiredErrorMessage,
} from "ente-accounts/services/passkey";
import {
stashKeyEncryptionKeyInSessionStore,
@@ -24,7 +23,7 @@ import {
} from "ente-accounts/services/session-storage";
import {
getSRPAttributes,
- srpVerificationUnauthorizedErrorMessage,
+ srpVerificationUnauthorizedErrorName,
verifySRP,
} from "ente-accounts/services/srp";
import {
@@ -74,9 +73,6 @@ export type SpaceLoginPasskeyStatusResult =
| SpaceLoginResult
| { status: "pending" };
-export const spaceLoginPasskeySessionExpiredErrorMessage =
- passkeySessionExpiredErrorMessage;
-
let pendingSpaceLoginCredentials: SpaceLoginInput | undefined;
const cleanedEmail = (email: string) => email.trim();
@@ -176,7 +172,7 @@ export const beginSpaceLogin = async ({
} catch (error) {
if (
error instanceof Error &&
- error.message == srpVerificationUnauthorizedErrorMessage
+ error.name == srpVerificationUnauthorizedErrorName
) {
throw spaceAuthError("incorrect_credentials", error);
}
diff --git a/web/packages/accounts/components/LoginComponents.tsx b/web/packages/accounts/components/LoginComponents.tsx
index 653d2bbf96..1b38c20605 100644
--- a/web/packages/accounts/components/LoginComponents.tsx
+++ b/web/packages/accounts/components/LoginComponents.tsx
@@ -2,7 +2,7 @@ import { CircularProgress, Stack, Typography, styled } from "@mui/material";
import { sessionExpiredDialogAttributes } from "ente-accounts/components/utils/dialog";
import {
checkPasskeyVerificationStatus,
- passkeySessionExpiredErrorMessage,
+ passkeySessionExpiredErrorName,
saveCredentialsAndNavigateTo,
} from "ente-accounts/services/passkey";
import { LinkButton } from "ente-base/components/LinkButton";
@@ -132,8 +132,7 @@ export const VerifyingPasskey: React.FC<VerifyingPasskeyProps> = ({
} catch (e) {
log.error("Passkey verification status check failed", e);
showMiniDialog(
- e instanceof Error &&
- e.message == passkeySessionExpiredErrorMessage
+ e instanceof Error && e.name == passkeySessionExpiredErrorName
? sessionExpiredDialogAttributes(logout)
: genericErrorDialogAttributes(),
);
diff --git a/web/packages/accounts/components/VerifyMasterPasswordForm.tsx b/web/packages/accounts/components/VerifyMasterPasswordForm.tsx
index c277acf677..98bbabe5bd 100644
--- a/web/packages/accounts/components/VerifyMasterPasswordForm.tsx
+++ b/web/packages/accounts/components/VerifyMasterPasswordForm.tsx
@@ -1,7 +1,7 @@
import { Input, TextField } from "@mui/material";
import { decryptBox, deriveKey } from "ente-accounts/services/crypto";
import {
- srpVerificationUnauthorizedErrorMessage,
+ srpVerificationUnauthorizedErrorName,
type SRPAttributes,
} from "ente-accounts/services/srp";
import type { KeyAttributes } from "ente-accounts/services/user";
@@ -124,7 +124,7 @@ export const VerifyMasterPasswordForm: React.FC<
} catch (e) {
if (
e instanceof Error &&
- e.message == srpVerificationUnauthorizedErrorMessage
+ e.name == srpVerificationUnauthorizedErrorName
) {
log.error("Incorrect password or no account", e);
setFieldError(t("incorrect_password_or_no_account"));
diff --git a/web/packages/accounts/services/passkey.ts b/web/packages/accounts/services/passkey.ts
index 31c1cef1e4..856ed5acbc 100644
--- a/web/packages/accounts/services/passkey.ts
+++ b/web/packages/accounts/services/passkey.ts
@@ -119,7 +119,7 @@ const getAccountsTokenAndURL = async () => {
.parse(await res.json());
};
-export const passkeySessionExpiredErrorMessage = "Passkey session has expired";
+export const passkeySessionExpiredErrorName = "passkey_session_expired";
export const checkPasskeyVerificationStatus = async (
sessionID: string,
@@ -129,8 +129,11 @@ export const checkPasskeyVerificationStatus = async (
{ headers: publicRequestHeaders() },
);
if (!res.ok) {
- if (res.status == 404 || res.status == 410)
- throw new Error(passkeySessionExpiredErrorMessage);
+ if (res.status == 404 || res.status == 410) {
+ const error = new Error("Passkey session has expired");
+ error.name = passkeySessionExpiredErrorName;
+ throw error;
+ }
// Remote uses 400 to indicate that verification is still pending.
if (res.status == 400) return undefined;
throw new HTTPError(res);
diff --git a/web/packages/accounts/services/srp.ts b/web/packages/accounts/services/srp.ts
index d9f2a6a6a9..cfc616fcfa 100644
--- a/web/packages/accounts/services/srp.ts
+++ b/web/packages/accounts/services/srp.ts
@@ -193,8 +193,8 @@ const updateSRPAndKeys = async (
return UpdateSRPAndKeysResponse.parse(await res.json());
};
-export const srpVerificationUnauthorizedErrorMessage =
- "SRP verification failed (HTTP 401 Unauthorized)";
+export const srpVerificationUnauthorizedErrorName =
+ "srp_verification_unauthorized";
const deriveSRPLoginSubKey = async (kek: string) => {
const kekSubKeyBytes = await deriveSubKeyBytes(kek, 32, 1, "loginctx");
@@ -263,7 +263,11 @@ const verifySRPSession = async ({
body: JSON.stringify({ sessionID, srpUserID, srpM1 }),
});
if (res.status == 401) {
- throw new Error(srpVerificationUnauthorizedErrorMessage);
+ const error = new Error(
+ "SRP verification failed (HTTP 401 Unauthorized)",
+ );
+ error.name = srpVerificationUnauthorizedErrorName;
+ throw error;
}
ensureOk(res);
return RemoteSRPVerificationResponse.parse(await res.json());