Skip to content

Commit a92311a

Browse files
authored
[v4] Fix window popup blocked for social login in iOS Safari when using useEmbeddedWallet hook (#2758)
1 parent e6b5d9c commit a92311a

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

.changeset/dirty-hairs-cross.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@thirdweb-dev/react": patch
3+
---
4+
5+
Fix window popup blocked for social login in iOS Safari when using `useEmbeddedWallet` hook

legacy_packages/react/src/evm/hooks/wallets/useEmbeddedWallet.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
} from "@thirdweb-dev/wallets";
1616
import { useCallback } from "react";
1717
import { embeddedWallet } from "../../../wallet/wallets/embeddedWallet/embeddedWallet";
18+
import { openOauthSignInWindow } from "../../../wallet/utils/openOauthSignInWindow";
1819

1920
/**
2021
* Hook to connect `EmbeddedWallet` which allows users to login via Email or social logins
@@ -130,6 +131,18 @@ export function useEmbeddedWallet() {
130131
}
131132
const wallet = create(embeddedWallet());
132133
try {
134+
// open window immediately to fix issue in iOS Safari
135+
// if not opened immediately, it adds a bit of delay between user click and opening the window which causes the popup to be blocked
136+
if (
137+
authParams.strategy === "apple" ||
138+
authParams.strategy === "facebook" ||
139+
authParams.strategy === "google"
140+
) {
141+
const win = openOauthSignInWindow(authParams.strategy);
142+
if (win) {
143+
authParams.openedWindow = win;
144+
}
145+
}
133146
const authResult = await wallet.authenticate(authParams);
134147
await wallet.connect({ authResult });
135148
setWallet(wallet);

legacy_packages/react/src/wallet/utils/openOauthSignInWindow.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function getWidthAndHeight(authOption: EmbeddedWalletOauthStrategy) {
2323

2424
export function openOauthSignInWindow(
2525
authOption: EmbeddedWalletOauthStrategy,
26-
themeObj: Theme,
26+
themeObj?: Theme,
2727
) {
2828
// open the popup in the center of the screen
2929
const { height, width } = getWidthAndHeight(authOption);
@@ -39,8 +39,8 @@ export function openOauthSignInWindow(
3939
const title = getBodyTitle(authOption);
4040
win.document.title = title;
4141
win.document.body.innerHTML = spinnerWindowHtml;
42-
win.document.body.style.background = themeObj.colors.modalBg;
43-
win.document.body.style.color = themeObj.colors.accentText;
42+
win.document.body.style.background = themeObj?.colors.modalBg || "black";
43+
win.document.body.style.color = themeObj?.colors.accentText || "white";
4444
}
4545

4646
// close it when current window is closed or refreshed

0 commit comments

Comments
 (0)