diff --git a/account-kit/react/src/components/auth/card/loading/oauth.tsx b/account-kit/react/src/components/auth/card/loading/oauth.tsx index 6a1ceef5fb..b243af8a36 100644 --- a/account-kit/react/src/components/auth/card/loading/oauth.tsx +++ b/account-kit/react/src/components/auth/card/loading/oauth.tsx @@ -1,3 +1,4 @@ +import { OauthCancelledError } from "@account-kit/signer"; import { useEffect } from "react"; import { useSignerStatus } from "../../../../hooks/useSignerStatus.js"; import { ContinueWithOAuth } from "../../../../icons/oauth.js"; @@ -5,7 +6,6 @@ import { capitalize } from "../../../../utils.js"; import { useAuthContext } from "../../context.js"; import { useOAuthVerify } from "../../hooks/useOAuthVerify.js"; import { ConnectionError } from "../error/connection-error.js"; -import { OauthCancelledError } from "@account-kit/signer"; export const CompletingOAuth = () => { const { isConnected } = useSignerStatus(); @@ -15,11 +15,7 @@ export const CompletingOAuth = () => { useEffect(() => { if (isConnected) { - if (authStep.createPasskeyAfter) { - setAuthStep({ type: "passkey_create" }); - } else { - setAuthStep({ type: "complete" }); - } + setAuthStep({ type: "complete" }); } else if (oauthWasCancelled) { setAuthStep({ type: "initial" }); } diff --git a/account-kit/react/src/components/auth/modal.tsx b/account-kit/react/src/components/auth/modal.tsx index 6da25f4acb..04317b7bb1 100644 --- a/account-kit/react/src/components/auth/modal.tsx +++ b/account-kit/react/src/components/auth/modal.tsx @@ -1,8 +1,8 @@ import { useCallback } from "react"; import { useNewUserSignup } from "../../hooks/internal/useNewUserSignup.js"; import { useAuthModal } from "../../hooks/useAuthModal.js"; -import { useSignerStatus } from "../../hooks/useSignerStatus.js"; import { useUiConfig } from "../../hooks/useUiConfig.js"; +import { useSignerStatus } from "../../index.js"; import { Dialog } from "../dialog/dialog.js"; import { AuthCardContent } from "./card/index.js"; import { useAuthContext } from "./context.js"; @@ -16,19 +16,19 @@ export const AuthModal = () => { }) ); - const { setAuthStep } = useAuthContext(); + const { setAuthStep, authStep } = useAuthContext(); const { isOpen, closeAuthModal, openAuthModal } = useAuthModal(); const handleSignup = useCallback(() => { - if (addPasskeyOnSignup && !isOpen) { + if (addPasskeyOnSignup) { openAuthModal(); setAuthStep({ type: "passkey_create", }); } - }, [addPasskeyOnSignup, isOpen, openAuthModal, setAuthStep]); + }, [addPasskeyOnSignup, openAuthModal, setAuthStep]); - useNewUserSignup(handleSignup, isConnected); + useNewUserSignup(handleSignup, isConnected && authStep.type === "complete"); return ( diff --git a/account-kit/react/src/hooks/useAuthModal.ts b/account-kit/react/src/hooks/useAuthModal.ts index 17fc83185a..06d4fcc6a7 100644 --- a/account-kit/react/src/hooks/useAuthModal.ts +++ b/account-kit/react/src/hooks/useAuthModal.ts @@ -33,7 +33,9 @@ export const useAuthModal = () => { ); const openAuthModal = useCallback(() => setModalOpen(true), [setModalOpen]); - const closeAuthModal = useCallback(() => setModalOpen(false), [setModalOpen]); + const closeAuthModal = useCallback(() => { + setModalOpen(false); + }, [setModalOpen]); return { isOpen, diff --git a/account-kit/signer/src/base.ts b/account-kit/signer/src/base.ts index ecd2a973ae..b07cbc107b 100644 --- a/account-kit/signer/src/base.ts +++ b/account-kit/signer/src/base.ts @@ -843,6 +843,11 @@ export abstract class BaseAlchemySigner } })(); + // trigger new user event on signer from client + this.inner.on("newUserSignup", () => { + this.emitNewUserEvent(true); + }); + this.store.setState({ status, error: null, diff --git a/account-kit/signer/src/client/index.ts b/account-kit/signer/src/client/index.ts index f7d4409be7..87fccdc50f 100644 --- a/account-kit/signer/src/client/index.ts +++ b/account-kit/signer/src/client/index.ts @@ -463,6 +463,7 @@ export class AlchemySignerWebClient extends BaseSignerClient "_blank", "popup,width=500,height=600" ); + const eventEmitter = this.eventEmitter; return new Promise((resolve, reject) => { const handleMessage = (event: MessageEvent) => { if (!event.data) { @@ -472,6 +473,7 @@ export class AlchemySignerWebClient extends BaseSignerClient alchemyBundle: bundle, alchemyOrgId: orgId, alchemyIdToken: idToken, + alchemyIsSignup: isSignup, alchemyError, } = event.data; if (bundle && orgId && idToken) { @@ -483,7 +485,13 @@ export class AlchemySignerWebClient extends BaseSignerClient connectedEventName: "connectedOauth", idToken, authenticatingType: "oauth", - }).then(resolve, reject); + }).then((user) => { + if (isSignup) { + eventEmitter.emit("newUserSignup"); + } + + resolve(user); + }, reject); } else if (alchemyError) { cleanup(); popup?.close(); diff --git a/account-kit/signer/src/client/types.ts b/account-kit/signer/src/client/types.ts index c0c980e3d6..152c611f98 100644 --- a/account-kit/signer/src/client/types.ts +++ b/account-kit/signer/src/client/types.ts @@ -142,6 +142,7 @@ export type AuthenticatingEventMetadata = { export type AlchemySignerClientEvents = { connected(user: User): void; + newUserSignup(): void; authenticating(data: AuthenticatingEventMetadata): void; connectedEmail(user: User, bundle: string): void; connectedPasskey(user: User): void; diff --git a/examples/embedded-accounts-quickstart b/examples/embedded-accounts-quickstart index e4d61eb57c..63d936ebe9 160000 --- a/examples/embedded-accounts-quickstart +++ b/examples/embedded-accounts-quickstart @@ -1 +1 @@ -Subproject commit e4d61eb57c094b0c566dfe8570fe04e11365e260 +Subproject commit 63d936ebe94c65e5a12e41805bee1a5e9a29ed96