Skip to content

Commit

Permalink
fix(ui-components): ensure the passkey prompt always shows up when qp…
Browse files Browse the repository at this point in the history
… is present
  • Loading branch information
moldy530 committed Sep 24, 2024
1 parent 47e0197 commit 5b1e843
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 18 deletions.
2 changes: 1 addition & 1 deletion aa-sdk/core/src/version.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This file is autogenerated by inject-version.ts. Any changes will be
// overwritten on commit!
export const VERSION = "4.0.0-beta.5";
export const VERSION = "4.0.0-beta.6";
2 changes: 1 addition & 1 deletion account-kit/core/src/version.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This file is autogenerated by inject-version.ts. Any changes will be
// overwritten on commit!
export const VERSION = "4.0.0-beta.5";
export const VERSION = "4.0.0-beta.6";
2 changes: 1 addition & 1 deletion account-kit/infra/src/version.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This file is autogenerated by inject-version.ts. Any changes will be
// overwritten on commit!
export const VERSION = "4.0.0-beta.5";
export const VERSION = "4.0.0-beta.6";
2 changes: 1 addition & 1 deletion account-kit/plugingen/src/version.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This file is autogenerated by inject-version.ts. Any changes will be
// overwritten on commit!
export const VERSION = "4.0.0-beta.5";
export const VERSION = "4.0.0-beta.6";
7 changes: 7 additions & 0 deletions account-kit/react/src/components/auth/card/passkey-added.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { AddedPasskeyIllustration } from "../../../icons/illustrations/added-passkey.js";
import { useAuthContext } from "../context.js";

// eslint-disable-next-line jsdoc/require-jsdoc
export function PasskeyAdded() {
const { setAuthStep } = useAuthContext();

setTimeout(() => {
setAuthStep({ type: "complete" });
}, 5000);

return (
<div className="flex flex-col gap-5 items-center">
<div className="flex flex-col items-center justify-center h-12 w-12">
Expand Down
33 changes: 21 additions & 12 deletions account-kit/react/src/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,21 @@ export const AlchemyAccountProvider = (
const openAuthModal = useCallback(() => setIsModalOpen(true), []);
const closeAuthModal = useCallback(() => setIsModalOpen(false), []);

const clearAuthParams = () => {
const url = new URL(window.location.href);
url.searchParams.delete("orgId");
url.searchParams.delete("bundle");
url.searchParams.delete(IS_SIGNUP_QP);
window.history.replaceState({}, "", url.toString());
};

/**
* Reset the auth step to the initial state. This also clears the email auth query params from the URL.
*/
const resetAuthStep = useCallback(() => {
setAuthStep({ type: "initial" });

const url = new URL(window.location.href);
url.searchParams.delete("orgId");
url.searchParams.delete("bundle");
url.searchParams.delete(IS_SIGNUP_QP);
window.history.replaceState({}, "", url.toString());
clearAuthParams();
}, []);

const initialContext = useMemo(
Expand All @@ -144,22 +148,27 @@ export const AlchemyAccountProvider = (
[config, queryClient, openAuthModal, closeAuthModal, isModalOpen]
);

const { status, isAuthenticating } = useSignerStatus(initialContext);
const { isAuthenticating, isConnected } = useSignerStatus(initialContext);
const [authStep, setAuthStep] = useState<AuthStep>({
type: isAuthenticating ? "email_completing" : "initial",
});

useEffect(() => {
const urlParams = new URLSearchParams(window.location.search);
if (
status === "AWAITING_EMAIL_AUTH" &&
config.ui?.auth?.addPasskeyOnSignup
isConnected &&
config.ui?.auth?.addPasskeyOnSignup &&
urlParams.get(IS_SIGNUP_QP) === "true"
) {
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.get(IS_SIGNUP_QP) !== "true") return;

openAuthModal();
}
}, [status, config.ui, openAuthModal]);
}, [config.ui, isConnected, openAuthModal]);

useEffect(() => {
if (authStep.type === "complete") {
clearAuthParams();
}
}, [authStep]);

return (
<Hydrate {...props}>
Expand Down
2 changes: 1 addition & 1 deletion account-kit/react/src/version.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This file is autogenerated by inject-version.ts. Any changes will be
// overwritten on commit!
export const VERSION = "4.0.0-beta.5";
export const VERSION = "4.0.0-beta.6";
2 changes: 1 addition & 1 deletion account-kit/signer/src/version.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This file is autogenerated by inject-version.ts. Any changes will be
// overwritten on commit!
export const VERSION = "4.0.0-beta.5";
export const VERSION = "4.0.0-beta.6";

0 comments on commit 5b1e843

Please sign in to comment.