Skip to content

armgit / ente

Public Imported from GitHub
0

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

Happy path

Manav Rathicc3f398a7812
diff --git a/web/packages/accounts/services/passkey.ts b/web/packages/accounts/services/passkey.ts
index 5438d06cab..7f4c848fe0 100644
--- a/web/packages/accounts/services/passkey.ts
+++ b/web/packages/accounts/services/passkey.ts
@@ -3,6 +3,7 @@ import log from "@/next/log";
import type { AppName } from "@/next/types/app";
import { clientPackageName } from "@/next/types/app";
import { TwoFactorAuthorizationResponse } from "@/next/types/credentials";
+import { ensure } from "@/utils/ensure";
import ComlinkCryptoWorker from "@ente/shared/crypto";
import { getRecoveryKey } from "@ente/shared/crypto/helpers";
import {
@@ -12,6 +13,8 @@ import {
import { CustomError } from "@ente/shared/error";
import HTTPService from "@ente/shared/network/HTTPService";
import { accountsAppURL, apiOrigin } from "@ente/shared/network/api";
+import InMemoryStore, { MS_KEYS } from "@ente/shared/storage/InMemoryStore";
+import { LS_KEYS, getData, setData } from "@ente/shared/storage/localStorage";
import { getToken } from "@ente/shared/storage/localStorage/helpers";
/**
@@ -237,3 +240,35 @@ export const checkPasskeyVerificationStatus = async (
}
return TwoFactorAuthorizationResponse.parse(await res.json());
};
+
+/**
+ * Extract credentials from a successful passkey verification response and save
+ * them to local storage for use by subsequent steps (or normal functioning) of
+ * the app.
+ *
+ * @param response The result of a successful
+ * {@link checkPasskeyVerificationStatus}.
+ *
+ * @returns the slug that we should navigate to now.
+ */
+export const saveCredentialsAndNavigateTo = (
+ response: TwoFactorAuthorizationResponse,
+) => {
+ // This method somewhat duplicates `saveCredentialsAndNavigateTo` in the
+ // /passkeys/finish page.
+ const { id, encryptedToken, keyAttributes } = response;
+
+ setData(LS_KEYS.USER, {
+ ...getData(LS_KEYS.USER),
+ encryptedToken,
+ id,
+ });
+ setData(LS_KEYS.KEY_ATTRIBUTES, ensure(keyAttributes));
+
+ // TODO(MR): Remove the cast.
+ const redirectURL = InMemoryStore.get(MS_KEYS.REDIRECT_URL) as
+ | string
+ | undefined;
+ InMemoryStore.delete(MS_KEYS.REDIRECT_URL);
+ return redirectURL ?? "/credentials";
+};
diff --git a/web/packages/shared/components/LoginComponents.tsx b/web/packages/shared/components/LoginComponents.tsx
index bb51306d2b..eef0a1bca5 100644
--- a/web/packages/shared/components/LoginComponents.tsx
+++ b/web/packages/shared/components/LoginComponents.tsx
@@ -3,6 +3,7 @@ import log from "@/next/log";
import {
checkPasskeyVerificationStatus,
passKeySessionExpiredErrorMessage,
+ saveCredentialsAndNavigateTo,
} from "@ente/accounts/services/passkey";
import EnteButton from "@ente/shared/components/EnteButton";
import { apiOrigin } from "@ente/shared/network/api";
@@ -101,11 +102,8 @@ export const VerifyingPasskey: React.FC<VerifyingPasskeyProps> = ({
try {
const response =
await checkPasskeyVerificationStatus(passkeySessionID);
- if (!response) {
- setVerificationStatus("pending");
- } else {
- // TODO-PK:
- }
+ if (!response) setVerificationStatus("pending");
+ else router.push(saveCredentialsAndNavigateTo(response));
} catch (e) {
log.error("Passkey verification status check failed", e);
setDialogBoxAttributesV2(
@@ -114,6 +112,7 @@ export const VerifyingPasskey: React.FC<VerifyingPasskeyProps> = ({
? sessionExpiredDialogAttributes(logout)
: genericErrorAttributes(),
);
+ setVerificationStatus("waiting");
}
};