π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Handle 401
Manav Rathi0e4522c2876d
diff --git a/web/apps/auth/src/pages/auth.tsx b/web/apps/auth/src/pages/auth.tsxindex c7151738ef..d104c36dda 100644--- a/web/apps/auth/src/pages/auth.tsx+++ b/web/apps/auth/src/pages/auth.tsx@@ -3,6 +3,7 @@ import { stashRedirect } from "@/accounts/services/redirect";import { EnteLogo } from "@/base/components/EnteLogo";import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";import { NavbarBase } from "@/base/components/Navbar";+import { isHTTP401Error } from "@/base/http";import log from "@/base/log";import { masterKeyFromSessionIfLoggedIn } from "@/base/session-store";import {@@ -12,7 +13,6 @@ import {import OverflowMenu from "@ente/shared/components/OverflowMenu/menu";import { OverflowMenuOption } from "@ente/shared/components/OverflowMenu/option";import { AUTH_PAGES as PAGES } from "@ente/shared/constants/pages";-import { ApiError } from "@ente/shared/error";import LogoutOutlined from "@mui/icons-material/LogoutOutlined";import MoreHoriz from "@mui/icons-material/MoreHoriz";import {@@ -54,10 +54,7 @@ const Page: React.FC = () => {setCodes(await getAuthCodes(masterKey));} catch (e) {log.error("Failed to fetch codes", e);- if (e instanceof ApiError && e.httpStatusCode == 401) {- // We get back a 401 Unauthorized if the token is not valid.- showSessionExpiredDialog();- }+ if (isHTTP401Error(e)) showSessionExpiredDialog();}setHasFetched(true);};diff --git a/web/apps/auth/src/services/remote.ts b/web/apps/auth/src/services/remote.tsindex 7cca599484..e312b70986 100644--- a/web/apps/auth/src/services/remote.ts+++ b/web/apps/auth/src/services/remote.ts@@ -2,7 +2,6 @@ import { decryptBoxB64, decryptMetadataJSON_New } from "@/base/crypto";import { authenticatedRequestHeaders, ensureOk, HTTPError } from "@/base/http";import log from "@/base/log";import { apiURL } from "@/base/origins";-import { masterKeyFromSession } from "@/base/session-store";import { ensureString } from "@/utils/ensure";import { codeFromURIString, type Code } from "services/code";import { z } from "zod";diff --git a/web/packages/base/http.ts b/web/packages/base/http.tsindex fe6941a8aa..fb0adaa652 100644--- a/web/packages/base/http.ts+++ b/web/packages/base/http.ts@@ -70,6 +70,15 @@ export const ensureOk = (res: Response) => {export const isHTTP4xxError = (e: unknown) =>e instanceof HTTPError && e.res.status >= 400 && e.res.status <= 499;+/**+ * Return true if this is a HTTP 401 error.+ *+ * For authenticated requests, an HTTP "401 Unauthorized" indicates that the+ * credentials (auth token) is not valid.+ */+export const isHTTP401Error = (e: unknown) =>+ e instanceof HTTPError && e.res.status == 401;+/*** A helper function to adapt {@link retryAsyncOperation} for HTTP fetches.*