Skip to content
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

Merged
merged 9 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
23 changes: 23 additions & 0 deletions .changeset/early-radios-begin.md
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
28 changes: 15 additions & 13 deletions packages/scaffold-ui/src/partials/w3m-social-login-widget/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,34 +237,36 @@ export class W3mSocialLoginWidget extends LitElement {

try {
if (authConnector && socialProvider) {
this.popupWindow = CoreHelperUtil.returnOpenHref(
Copy link
Contributor

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

'',
'popupWindow',
'width=600,height=800,scrollbars=yes'
)

if (this.popupWindow) {
AccountController.setSocialWindow(this.popupWindow, ChainController.state.activeChain)
} else {
throw new Error('Something went wrong')
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

does this impact TG integration @ganchoradkov ?

Copy link
Member

Choose a reason for hiding this comment

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

most likely yes, this.popupWindow is undefined in telegram context so the logic will not continue with this throw

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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()
Expand Down
64 changes: 64 additions & 0 deletions packages/scaffold-ui/test/partials/w3m-social-login-widget.test.ts
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')
Copy link
Contributor

Choose a reason for hiding this comment

The 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)
})
})
Loading