-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: social login popup blocked by safari #3878
Changes from 3 commits
78871a6
a647c33
c15e4a1
68ec467
227490a
f195f59
3b4a10e
42a2621
79596e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
'@reown/appkit-scaffold-ui': patch | ||
'@reown/appkit-adapter-bitcoin': patch | ||
'@reown/appkit-adapter-ethers': patch | ||
'@reown/appkit-adapter-ethers5': patch | ||
'@reown/appkit-adapter-solana': patch | ||
'@reown/appkit-adapter-wagmi': patch | ||
'@reown/appkit': patch | ||
'@reown/appkit-utils': patch | ||
'@reown/appkit-cdn': patch | ||
'@reown/appkit-cli': patch | ||
'@reown/appkit-common': patch | ||
'@reown/appkit-core': patch | ||
'@reown/appkit-experimental': patch | ||
'@reown/appkit-polyfills': patch | ||
'@reown/appkit-siwe': patch | ||
'@reown/appkit-siwx': patch | ||
'@reown/appkit-ui': patch | ||
'@reown/appkit-wallet': patch | ||
'@reown/appkit-wallet-button': patch | ||
--- | ||
|
||
Fixed an issue where social popup window was blocked by safari |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -237,34 +237,36 @@ export class W3mSocialLoginWidget extends LitElement { | |
|
||
try { | ||
if (authConnector && socialProvider) { | ||
this.popupWindow = CoreHelperUtil.returnOpenHref( | ||
'', | ||
'popupWindow', | ||
'width=600,height=800,scrollbars=yes' | ||
) | ||
|
||
if (this.popupWindow) { | ||
AccountController.setSocialWindow(this.popupWindow, ChainController.state.activeChain) | ||
} else { | ||
throw new Error('Something went wrong') | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this impact TG integration @ganchoradkov ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. most likely yes, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pushed a change |
||
const { uri } = await authConnector.provider.getSocialRedirectUri({ | ||
provider: socialProvider | ||
}) | ||
|
||
if (!uri) { | ||
this.popupWindow.close() | ||
throw new Error('Something went wrong') | ||
} | ||
|
||
this.popupWindow.location.href = uri | ||
|
||
if (CoreHelperUtil.isTelegram()) { | ||
SafeLocalStorage.setItem(SafeLocalStorageKeys.SOCIAL_PROVIDER, socialProvider) | ||
const parsedUri = CoreHelperUtil.formatTelegramSocialLoginUrl(uri) | ||
|
||
// eslint-disable-next-line consistent-return | ||
return CoreHelperUtil.openHref(parsedUri, '_top') | ||
} | ||
|
||
this.popupWindow = CoreHelperUtil.returnOpenHref( | ||
'', | ||
'popupWindow', | ||
'width=600,height=800,scrollbars=yes' | ||
) | ||
|
||
if (this.popupWindow) { | ||
AccountController.setSocialWindow(this.popupWindow, ChainController.state.activeChain) | ||
this.popupWindow.location.href = uri | ||
} else { | ||
throw new Error('Something went wrong') | ||
} | ||
} | ||
} catch (error) { | ||
this.popupWindow?.close() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { fixture } from '@open-wc/testing' | ||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
||
import { html } from 'lit' | ||
|
||
import { | ||
AccountController, | ||
type AuthConnector, | ||
ChainController, | ||
ConnectorController, | ||
CoreHelperUtil, | ||
EventsController, | ||
OptionsController, | ||
RouterController | ||
} from '@reown/appkit-core' | ||
|
||
import { W3mSocialLoginWidget } from '../../src/partials/w3m-social-login-widget' | ||
import { HelpersUtil } from '../utils/HelpersUtil' | ||
|
||
describe('W3mSocialLoginWidget', () => { | ||
beforeEach(() => { | ||
vi.clearAllMocks() | ||
}) | ||
|
||
afterEach(() => { | ||
vi.restoreAllMocks() | ||
}) | ||
|
||
it('should handle standard social login flow when clicking Google button', async () => { | ||
const mockWindow = { location: { href: '' } } | ||
const mockUri = 'https://auth.example.com/login' | ||
|
||
vi.spyOn(OptionsController.state, 'features', 'get').mockReturnValue({ | ||
...OptionsController.state.features, | ||
socials: ['google'] | ||
}) | ||
vi.spyOn(AccountController, 'setSocialProvider') | ||
vi.spyOn(EventsController, 'sendEvent') | ||
vi.spyOn(RouterController, 'push') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to spyOn these if we don't check them if they are called or not? |
||
vi.spyOn(CoreHelperUtil, 'returnOpenHref').mockReturnValue(mockWindow as Window) | ||
vi.spyOn(ChainController.state, 'activeChain', 'get').mockReturnValue('eip155') | ||
vi.spyOn(ConnectorController, 'getAuthConnector').mockReturnValue({ | ||
provider: { | ||
getSocialRedirectUri: vi.fn().mockResolvedValue({ uri: mockUri }) | ||
} | ||
} as unknown as AuthConnector) | ||
vi.spyOn(AccountController, 'setSocialWindow') | ||
|
||
const element: W3mSocialLoginWidget = await fixture( | ||
html`<w3m-social-login-widget></w3m-social-login-widget>` | ||
) | ||
|
||
const googleButton = HelpersUtil.getByTestId(element, 'social-selector-google') | ||
await googleButton.click() | ||
|
||
expect(CoreHelperUtil.returnOpenHref).toHaveBeenCalledWith( | ||
'', | ||
'popupWindow', | ||
'width=600,height=800,scrollbars=yes' | ||
) | ||
expect(AccountController.setSocialWindow).toHaveBeenCalledWith(mockWindow, 'eip155') | ||
expect(mockWindow.location.href).toBe(mockUri) | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We open new window here and also opening new window in
(CoreHelperUtil.isTelegram()) {...}
. Not sure if this breaks stuff in telegram