Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/every-sides-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Automatically trigger SIWE sign in when a wallet is connected
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { LockIcon } from "./icons/LockIcon.js";
import { useConnectLocale } from "./locale/getConnectLocale.js";
import type { ConnectLocale } from "./locale/types.js";
import { SignatureScreen } from "./screens/SignatureScreen.js";
import { useAdminWallet } from "src/exports/react.native.js";

const TW_CONNECT_WALLET = "tw-connect-wallet";

Expand Down Expand Up @@ -400,6 +401,7 @@ function ConnectButtonInner(
) {
const activeWallet = useActiveWallet();
const activeAccount = useActiveAccount();
const adminWallet = useAdminWallet();
const siweAuth = useSiweAuth(activeWallet, activeAccount, props.auth);
const [showSignatureModal, setShowSignatureModal] = useState(false);

Expand All @@ -410,6 +412,28 @@ function ConnectButtonInner(
}
}, [activeAccount]);

// if an IAW wallet is connected and auth is required, trigger a login attempt automatically
useEffect(() => {
const isIAW = activeWallet?.id === "inApp" || adminWallet?.id === "inApp";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we have a helper for this? That handles smart and ecosystem too

if (
activeAccount &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should only do this for in app wallets. Coz on mobile you really need an explicit click otherwise things break quickly.

siweAuth.requiresAuth &&
!siweAuth.isLoggedIn &&
!siweAuth.isLoggingIn &&
isIAW
) {
siweAuth.doLogin();
}
}, [
activeAccount,
siweAuth.requiresAuth,
siweAuth.doLogin,
siweAuth.isLoggedIn,
siweAuth.isLoggingIn,
activeWallet,
adminWallet,
]);

const theme = props.theme || "dark";
const connectionStatus = useActiveWalletConnectionStatus();
const locale = props.connectLocale;
Expand Down
Loading