From d94d74818553fb406a24555186e65eaa0a6c16b6 Mon Sep 17 00:00:00 2001 From: Gio Martinez Date: Tue, 30 Sep 2025 18:28:56 -0400 Subject: [PATCH 1/2] Refresh user after linking account --- .../components/LinkAccount/LinkAccount.tsx | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/sdk/src/global-account/react/components/LinkAccount/LinkAccount.tsx b/packages/sdk/src/global-account/react/components/LinkAccount/LinkAccount.tsx index 39596af63..788b40e07 100644 --- a/packages/sdk/src/global-account/react/components/LinkAccount/LinkAccount.tsx +++ b/packages/sdk/src/global-account/react/components/LinkAccount/LinkAccount.tsx @@ -1,13 +1,14 @@ import app from "@b3dotfun/sdk/global-account/app"; import { ecosystemWalletId } from "@b3dotfun/sdk/shared/constants"; import { thirdwebB3Mainnet } from "@b3dotfun/sdk/shared/constants/chains/b3Chain"; +import { debugB3React } from "@b3dotfun/sdk/shared/utils/debug"; import { client } from "@b3dotfun/sdk/shared/utils/thirdweb"; import { Loader2, Mail, Phone, WalletIcon } from "lucide-react"; import { useCallback, useEffect, useState } from "react"; import { toast } from "sonner"; import { useLinkProfile, useProfiles } from "thirdweb/react"; -import { createWallet, preAuthenticate, WalletId } from "thirdweb/wallets"; -import { WalletRow } from "../.."; +import { Account, createWallet, preAuthenticate, WalletId } from "thirdweb/wallets"; +import { useSiwe, WalletRow } from "../.."; import { LinkAccountModalProps, useModalStore } from "../../stores/useModalStore"; import { getProfileDisplayInfo } from "../../utils/profileDisplay"; import { useB3 } from "../B3Provider/useB3"; @@ -21,6 +22,7 @@ type OTPStrategy = "email" | "phone"; type SocialStrategy = "google" | "x" | "discord" | "apple" | "farcaster"; type Strategy = OTPStrategy | SocialStrategy | "wallet"; +const debug = debugB3React("LinkAccount"); interface AuthMethod { id: Strategy; label: string; @@ -93,6 +95,8 @@ export function LinkAccount({ const [otpSent, setOtpSent] = useState(false); const [error, setError] = useState(null); const { data: profilesRaw = [] } = useProfiles({ client }); + const { account, setUser } = useB3(); + const { authenticate } = useSiwe(); // Get connected auth methods const connectedAuthMethods = profilesRaw @@ -111,10 +115,20 @@ export function LinkAccount({ originalProfile: profile, })); - const { account } = useB3(); const { mutate: linkProfile } = useLinkProfile(); const onSuccess = useCallback(async () => { + // Update user on success + // Try to re-authenticate first + try { + const userAuth = await app.reAuthenticate(); + setUser(userAuth.user); + } catch (error) { + // If re-authentication fails, try fresh authentication + debug("Re-authentication failed, attempting fresh authentication"); + const userAuth = await authenticate(account as Account, partnerId); + debug("Fresh authentication successful", { userAuth }); + } await onSuccessCallback?.(); }, [onSuccessCallback]); From 13021d6e543ca1f18a9efabfd641a7f7bddba556 Mon Sep 17 00:00:00 2001 From: Gio Martinez Date: Tue, 30 Sep 2025 18:33:02 -0400 Subject: [PATCH 2/2] update deps + add log --- .../react/components/LinkAccount/LinkAccount.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/sdk/src/global-account/react/components/LinkAccount/LinkAccount.tsx b/packages/sdk/src/global-account/react/components/LinkAccount/LinkAccount.tsx index 788b40e07..1b9bd2c51 100644 --- a/packages/sdk/src/global-account/react/components/LinkAccount/LinkAccount.tsx +++ b/packages/sdk/src/global-account/react/components/LinkAccount/LinkAccount.tsx @@ -122,6 +122,7 @@ export function LinkAccount({ // Try to re-authenticate first try { const userAuth = await app.reAuthenticate(); + console.log("@@setting user", userAuth) setUser(userAuth.user); } catch (error) { // If re-authentication fails, try fresh authentication @@ -130,7 +131,7 @@ export function LinkAccount({ debug("Fresh authentication successful", { userAuth }); } await onSuccessCallback?.(); - }, [onSuccessCallback]); + }, [onSuccessCallback, setUser, account, partnerId, authenticate]); // Reset linking state when component unmounts useEffect(() => {