From 34185de13d20308bfa8722a303a2d54f226ffb43 Mon Sep 17 00:00:00 2001 From: David Philipson Date: Wed, 16 Oct 2024 14:21:46 -0700 Subject: [PATCH] fix: don't show error view when cancelling oauth This is an intentional action from the user and not an error. Instead, just return to the main screen. --- account-kit/react/package.json | 1 + .../src/components/auth/card/loading/oauth.tsx | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/account-kit/react/package.json b/account-kit/react/package.json index 8fa2840bbd..7aaa1b4606 100644 --- a/account-kit/react/package.json +++ b/account-kit/react/package.json @@ -70,6 +70,7 @@ "@account-kit/core": "^4.3.1", "@account-kit/infra": "^4.3.1", "@account-kit/logging": "^4.3.1", + "@account-kit/signer": "^4.3.1", "@tanstack/react-form": "^0.33.0", "@tanstack/zod-form-adapter": "^0.33.0", "@wagmi/connectors": "^5.1.15", 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 c592832c58..6a1ceef5fb 100644 --- a/account-kit/react/src/components/auth/card/loading/oauth.tsx +++ b/account-kit/react/src/components/auth/card/loading/oauth.tsx @@ -5,11 +5,13 @@ 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(); const { setAuthStep, authStep } = useAuthContext("oauth_completing"); const { authenticate } = useOAuthVerify({ config: authStep.config }); + const oauthWasCancelled = authStep.error instanceof OauthCancelledError; useEffect(() => { if (isConnected) { @@ -18,10 +20,17 @@ export const CompletingOAuth = () => { } else { setAuthStep({ type: "complete" }); } + } else if (oauthWasCancelled) { + setAuthStep({ type: "initial" }); } - }, [authStep.createPasskeyAfter, isConnected, setAuthStep]); + }, [ + authStep.createPasskeyAfter, + isConnected, + oauthWasCancelled, + setAuthStep, + ]); - if (authStep.error) { + if (authStep.error && !oauthWasCancelled) { return (