Skip to content

Commit

Permalink
fix: Remove sso iframe (#2126)
Browse files Browse the repository at this point in the history
  • Loading branch information
fzavalia authored Feb 8, 2024
1 parent 0488ff4 commit ecaaf9e
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 26 deletions.
1 change: 0 additions & 1 deletion webapp/src/config/env/dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"EXPLORER_URL": "https://play.decentraland.zone",
"MARKETPLACE_URL": "https://decentraland.zone/marketplace",
"PROFILE_URL": "https://decentraland.zone/profile",
"SSO_URL": "https://id.decentraland.zone",
"SUBGRAPH_WORKER": "https://subgraph.decentraland.zone",
"SENTRY_DSN": "https://1dc401149e1c819b8477565c9cdd9b70@o4504361728212992.ingest.sentry.io/4505743351676928",
"SQUID_API_URL": "https://testnet.v2.api.squidrouter.com/",
Expand Down
1 change: 0 additions & 1 deletion webapp/src/config/env/prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"EXPLORER_URL": "https://play.decentraland.org",
"MARKETPLACE_URL": "https://decentraland.org/marketplace",
"PROFILE_URL": "https://decentraland.org/profile",
"SSO_URL": "https://id.decentraland.org",
"SUBGRAPH_WORKER": "https://subgraph.decentraland.org",
"SENTRY_DSN": "https://1dc401149e1c819b8477565c9cdd9b70@o4504361728212992.ingest.sentry.io/4505743351676928",
"SQUID_API_URL": "https://v2.api.squidrouter.com",
Expand Down
1 change: 0 additions & 1 deletion webapp/src/config/env/stg.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"EXPLORER_URL": "https://play.decentraland.org",
"MARKETPLACE_URL": "https://decentraland.today/marketplace",
"PROFILE_URL": "https://decentraland.today/profile",
"SSO_URL": "https://id.decentraland.today",
"SUBGRAPH_WORKER": "https://subgraph.decentraland.today",
"SENTRY_DSN": "https://1dc401149e1c819b8477565c9cdd9b70@o4504361728212992.ingest.sentry.io/4505743351676928",
"SQUID_API_URL": "https://v2.api.squidrouter.com",
Expand Down
7 changes: 0 additions & 7 deletions webapp/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import ReactDOM from 'react-dom'
import { Provider } from 'react-redux'

import { ConnectedRouter } from 'connected-react-router'
import * as SingleSignOn from '@dcl/single-sign-on-client'
import WalletProvider from 'decentraland-dapps/dist/providers/WalletProvider'
import ToastProvider from 'decentraland-dapps/dist/providers/ToastProvider'
import TranslationProvider from 'decentraland-dapps/dist/providers/TranslationProvider'
Expand All @@ -16,16 +15,10 @@ import * as locales from './modules/translation/locales'
import { initStore, createHistory } from './modules/store'
import { Routes } from './components/Routes'
import * as modals from './components/Modals'
import { config } from './config'

import './themes'
import './index.css'

// Initializes the SSO client.
// This will create a new iframe and append it to the body.
// It is ideal to do this as soon as possible to avoid any availability issues.
SingleSignOn.init(config.get('SSO_URL'))

const history = createHistory()
const store = initStore(history)

Expand Down
12 changes: 4 additions & 8 deletions webapp/src/modules/identity/sagas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import {
disconnectWallet
} from 'decentraland-dapps/dist/modules/wallet/actions'
import {
getIdentity,
clearIdentity,
localStorageClearIdentity,
localStorageGetIdentity
} from '@dcl/single-sign-on-client'
Expand All @@ -18,8 +16,6 @@ import { AuthIdentity } from '@dcl/crypto'

jest.mock('@dcl/single-sign-on-client', () => {
return {
getIdentity: jest.fn(),
clearIdentity: jest.fn(),
localStorageClearIdentity: jest.fn(),
localStorageGetIdentity: jest.fn(),
localStorageStoreIdentity: jest.fn()
Expand Down Expand Up @@ -88,7 +84,7 @@ describe('when handling the wallet connection success', () => {
it('should put an action to generate the identity', () => {
return expectSaga(identitySaga)
.provide([
[call(getIdentity, wallet.address), null],
[call(localStorageGetIdentity, wallet.address), null],
[select(getIsAuthDappEnabled), false]
])
.put(generateIdentityRequest(wallet.address))
Expand All @@ -103,7 +99,7 @@ describe('when handling the wallet connection success', () => {

return expectSaga(identitySaga)
.provide([
[call(getIdentity, wallet.address), identity],
[call(localStorageGetIdentity, wallet.address), identity],
[select(getIsAuthDappEnabled), false]
])
.put(generateIdentitySuccess(wallet.address, identity))
Expand Down Expand Up @@ -140,7 +136,7 @@ describe('when handling the disconnect', () => {
.dispatch(disconnectWallet())
.run({ silenceTimeout: true })

expect(clearIdentity).toHaveBeenCalledWith(address)
expect(localStorageClearIdentity).toHaveBeenCalledWith(address)
})
})
})
Expand All @@ -155,7 +151,7 @@ describe('when handling the disconnect', () => {
.dispatch(disconnectWallet())
.run({ silenceTimeout: true })

expect(clearIdentity).not.toHaveBeenCalled()
expect(localStorageClearIdentity).not.toHaveBeenCalled()
})
})
})
19 changes: 11 additions & 8 deletions webapp/src/modules/identity/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import { takeLatest, put, call, select } from 'redux-saga/effects'
import { ethers } from 'ethers'
import { Authenticator, AuthIdentity } from '@dcl/crypto'
import {
getIdentity,
storeIdentity,
clearIdentity,
localStorageGetIdentity,
localStorageClearIdentity
localStorageClearIdentity,
localStorageStoreIdentity
} from '@dcl/single-sign-on-client'
import { t } from 'decentraland-dapps/dist/modules/translation/utils'
import {
Expand Down Expand Up @@ -58,7 +56,7 @@ function* handleGenerateIdentityRequest(action: GenerateIdentityRequestAction) {
)

// Stores the identity into the SSO iframe.
yield call(storeIdentity, address, identity)
yield call(localStorageStoreIdentity, address, identity)

yield put(generateIdentitySuccess(address, identity))
} catch (error) {
Expand Down Expand Up @@ -92,14 +90,19 @@ function* handleConnectWalletSuccess(action: ConnectWalletSuccessAction) {
yield put(generateIdentitySuccess(address, identity))
} else {
window.location.replace(
`${config.get('AUTH_URL')}/login?redirectTo=${encodeURIComponent(window.location.href)}`
`${config.get('AUTH_URL')}/login?redirectTo=${encodeURIComponent(
window.location.href
)}`
)
}
return
}

// Obtains the identity from the SSO iframe.
const identity: AuthIdentity | null = yield call(getIdentity, address)
const identity: AuthIdentity | null = yield call(
localStorageGetIdentity,
address
)

// If the identity was persisted in the iframe, store in in redux.
// If not, generate a new one, which wil be stored in the iframe.
Expand All @@ -117,7 +120,7 @@ function* handleDisconnect(_action: DisconnectWalletAction) {
localStorageClearIdentity(auxAddress)
} else {
// Clears the identity from the SSO iframe when the user disconnects the wallet.
yield call(clearIdentity, auxAddress)
yield call(localStorageClearIdentity, auxAddress)
}
}
}

0 comments on commit ecaaf9e

Please sign in to comment.