Skip to content

armgit / ente

Public Imported from GitHub
0

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

logSet the inflight session

Manav Rathi608fec91295b
diff --git a/web/packages/accounts/pages/credentials.tsx b/web/packages/accounts/pages/credentials.tsx
index 04bb51a8b1..811c5b975a 100644
--- a/web/packages/accounts/pages/credentials.tsx
+++ b/web/packages/accounts/pages/credentials.tsx
@@ -66,8 +66,8 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
const [srpAttributes, setSrpAttributes] = useState<SRPAttributes>();
const [keyAttributes, setKeyAttributes] = useState<KeyAttributes>();
const [user, setUser] = useState<User>();
- const [passkeyVerificationURL, setPasskeyVerificationURL] = useState<
- string | undefined
+ const [passkeyVerificationData, setPasskeyVerificationData] = useState<
+ [string, string] | undefined
>();
const router = useRouter();
@@ -180,8 +180,8 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
appName,
passkeySessionID,
);
- setPasskeyVerificationURL(url);
- openPasskeyVerificationURL(url);
+ setPasskeyVerificationData([passkeySessionID, url]);
+ openPasskeyVerificationURL(passkeySessionID, url);
throw Error(CustomError.TWO_FACTOR_ENABLED);
} else if (twoFactorSessionID) {
const sessionKeyAttributes =
@@ -274,12 +274,13 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
);
}
- if (passkeyVerificationURL) {
- // We only need when running in the desktop app, because in the web app
- // we just redirect to passkeyVerificationURL. However, still we add an
- // additional `globalThis.electron` check to show a spinner to prevent
- // all these details from being disorientingly shown for a fraction of a
- // second as the redirect happens on the web app.
+ if (passkeyVerificationData) {
+ // We only need to handle this scenario when running in the desktop app
+ // because the web app will navigate to Passkey verification URL.
+ // However, still we add an additional `globalThis.electron` check to
+ // show a spinner. This prevents the VerifyingPasskey component from
+ // being disorientingly shown for a fraction of a second as the redirect
+ // happens on the web app.
//
// See: [Note: Passkey verification in the desktop app]
@@ -295,7 +296,7 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
<VerifyingPasskey
email={user?.email}
onRetry={() =>
- openPasskeyVerificationURL(passkeyVerificationURL)
+ openPasskeyVerificationURL(...passkeyVerificationData)
}
onRecover={() => router.push("/passkeys/recover")}
onLogout={logout}
diff --git a/web/packages/accounts/pages/passkeys/finish.tsx b/web/packages/accounts/pages/passkeys/finish.tsx
index ff82938129..abbc328f9c 100644
--- a/web/packages/accounts/pages/passkeys/finish.tsx
+++ b/web/packages/accounts/pages/passkeys/finish.tsx
@@ -1,3 +1,4 @@
+import log from "@/next/log";
import { nullToUndefined } from "@/utils/transform";
import { VerticallyCentered } from "@ente/shared/components/Container";
import EnteSpinner from "@ente/shared/components/EnteSpinner";
@@ -79,6 +80,9 @@ const saveCredentialsAndNavigateTo = async (response: string) => {
// This is not the princess we were looking for. However, we have
// already entered this castle. Redirect back to home without changing
// any state, hopefully this will get the user back to where they were.
+ log.info(
+ `Ignoring redirect for unexpected passkeySessionID ${passkeySessionID}`,
+ );
return "/";
}
diff --git a/web/packages/accounts/pages/verify.tsx b/web/packages/accounts/pages/verify.tsx
index daad935607..1848b38be8 100644
--- a/web/packages/accounts/pages/verify.tsx
+++ b/web/packages/accounts/pages/verify.tsx
@@ -41,8 +41,8 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
const [email, setEmail] = useState("");
const [resend, setResend] = useState(0);
- const [passkeyVerificationURL, setPasskeyVerificationURL] = useState<
- string | undefined
+ const [passkeyVerificationData, setPasskeyVerificationData] = useState<
+ [string, string] | undefined
>();
const router = useRouter();
@@ -98,8 +98,8 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
appName,
passkeySessionID,
);
- setPasskeyVerificationURL(url);
- openPasskeyVerificationURL(url);
+ setPasskeyVerificationData([passkeySessionID, url]);
+ openPasskeyVerificationURL(passkeySessionID, url);
} else if (twoFactorSessionID) {
setData(LS_KEYS.USER, {
email,
@@ -172,12 +172,13 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
);
}
- if (passkeyVerificationURL) {
- // We only need when running in the desktop app, because in the web app
- // we just redirect to passkeyVerificationURL. However, still we add an
- // additional `globalThis.electron` check to show a spinner to prevent
- // all these details from being disorientingly shown for a fraction of a
- // second as the redirect happens on the web app.
+ if (passkeyVerificationData) {
+ // We only need to handle this scenario when running in the desktop app
+ // because the web app will navigate to Passkey verification URL.
+ // However, still we add an additional `globalThis.electron` check to
+ // show a spinner. This prevents the VerifyingPasskey component from
+ // being disorientingly shown for a fraction of a second as the redirect
+ // happens on the web app.
//
// See: [Note: Passkey verification in the desktop app]
@@ -193,7 +194,7 @@ const Page: React.FC<PageProps> = ({ appContext }) => {
<VerifyingPasskey
email={email}
onRetry={() =>
- openPasskeyVerificationURL(passkeyVerificationURL)
+ openPasskeyVerificationURL(...passkeyVerificationData)
}
onRecover={() => router.push("/passkeys/recover")}
onLogout={logout}
diff --git a/web/packages/accounts/services/passkey.ts b/web/packages/accounts/services/passkey.ts
index d8fb16edb1..d2e854e64d 100644
--- a/web/packages/accounts/services/passkey.ts
+++ b/web/packages/accounts/services/passkey.ts
@@ -50,6 +50,10 @@ export const passkeyVerificationRedirectURL = (
* Open or redirect to a passkey verification URL previously constructed using
* {@link passkeyVerificationRedirectURL}.
*
+ * @param passkeySessionID The passkeySessionID for which we are redirecting.
+ * This is saved to session storage to allow us to ignore subsequent redirects
+ * to the passkey flow finish page except the ones for this specific session.
+ *
* @param url The URL to redirect to or open in the system browser.
*
* [Note: Passkey verification in the desktop app]
@@ -71,7 +75,12 @@ export const passkeyVerificationRedirectURL = (
* authentication happens at accounts.ente.io, and on success there is
* redirected back to the desktop app.
*/
-export const openPasskeyVerificationURL = (url: string) => {
+export const openPasskeyVerificationURL = (
+ passkeySessionID: string,
+ url: string,
+) => {
+ sessionStorage.setItem("inflightPasskeySessionID", passkeySessionID);
+
if (globalThis.electron) window.open(url);
else window.location.href = url;
};