Skip to content

Commit

Permalink
fix: Remove auth flag
Browse files Browse the repository at this point in the history
  • Loading branch information
fzavalia committed Feb 8, 2024
1 parent a380aa7 commit 3b0bfb0
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 167 deletions.
6 changes: 1 addition & 5 deletions webapp/src/components/Navbar/Navbar.container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import { isPending } from 'decentraland-dapps/dist/modules/transaction/utils'

import { RootState } from '../../modules/reducer'
import { getTransactions } from '../../modules/transaction/selectors'
import {
getIsAuthDappEnabled,
} from '../../modules/features/selectors'
import { MapStateProps, MapDispatch, MapDispatchProps } from './Navbar.types'
import Navbar from './Navbar'
import { getCurrentIdentity } from '../../modules/identity/selectors'
Expand All @@ -17,8 +14,7 @@ const mapState = (state: RootState): MapStateProps => ({
hasPendingTransactions: getTransactions(state).some((tx: { status: TransactionStatus | null }) =>
isPending(tx.status)
),
identity: getCurrentIdentity(state) || undefined,
isAuthDappEnabled: getIsAuthDappEnabled(state),
identity: getCurrentIdentity(state) || undefined
})

const mapDispatch = (dispatch: MapDispatch): MapDispatchProps => ({
Expand Down
15 changes: 6 additions & 9 deletions webapp/src/components/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Props } from './Navbar.types'
import './Navbar.css'

const Navbar = (props: Props) => {
const { location, onNavigate, isAuthDappEnabled } = props
const { location, onNavigate } = props
const { pathname, search } = location

const handleOnSignIn = useCallback(() => {
Expand All @@ -21,14 +21,11 @@ const Navbar = (props: Props) => {
const redirectTo = !currentRedirectTo
? `${basename}${pathname}${search}`
: `${basename}${currentRedirectTo}`
if (isAuthDappEnabled) {
window.location.replace(
`${config.get('AUTH_URL')}/login?redirectTo=${redirectTo}`
)
} else {
onNavigate(locations.signIn(redirectTo))
}
}, [onNavigate, pathname, search, isAuthDappEnabled])

window.location.replace(
`${config.get('AUTH_URL')}/login?redirectTo=${redirectTo}`
)
}, [pathname, search])

const handleOnClickAccount = useCallback(() => {
onNavigate(locations.settings())
Expand Down
6 changes: 1 addition & 5 deletions webapp/src/components/Navbar/Navbar.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ export type Props = Partial<NavbarProps> & {
enablePartialSupportAlert?: boolean
onNavigate: (path: string) => void
identity?: AuthIdentity
isAuthDappEnabled: boolean
}

export type OwnProps = Pick<Props, 'enablePartialSupportAlert'>

export type MapStateProps = Pick<
Props,
| 'location'
| 'hasPendingTransactions'
| 'identity'
| 'isAuthDappEnabled'
'location' | 'hasPendingTransactions' | 'identity'
>
export type MapDispatchProps = Pick<Props, 'onNavigate'>
export type MapDispatch = Dispatch<CallHistoryMethodAction>
2 changes: 0 additions & 2 deletions webapp/src/components/SignInPage/SignInPage.container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import {
isConnected
} from 'decentraland-dapps/dist/modules/wallet/selectors'
import { RootState } from '../../modules/reducer'
import { getIsAuthDappEnabled } from '../../modules/features/selectors'
import { MapStateProps } from './SignInPage.types'
import SignInPage from './SignInPage'

const mapState = (state: RootState): MapStateProps => {
return {
isAuthDappEnabled: getIsAuthDappEnabled(state),
isConnecting: isConnecting(state),
isConnected: isConnected(state)
}
Expand Down
5 changes: 3 additions & 2 deletions webapp/src/components/SignInPage/SignInPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { Props } from './SignInPage.types'
import './SignInPage.css'

const SignInPage = (props: Props) => {
const { isAuthDappEnabled, isConnecting, isConnected } = props
const { isConnecting, isConnected } = props

const handleConnect = useCallback(() => {
if (!isConnected && !isConnecting) {
const params = new URLSearchParams(window.location.search)
Expand All @@ -29,7 +30,7 @@ const SignInPage = (props: Props) => {
<>
<Navbar />
<Page className="SignInPage" isFullscreen>
<SignIn onConnect={isAuthDappEnabled ? handleConnect : undefined} />
<SignIn onConnect={handleConnect} />
</Page>
<Footer isFullscreen />
</>
Expand Down
6 changes: 1 addition & 5 deletions webapp/src/components/SignInPage/SignInPage.types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
export type Props = {
isAuthDappEnabled: boolean
isConnecting: boolean
isConnected: boolean
}

export type MapStateProps = Pick<
Props,
'isAuthDappEnabled' | 'isConnected' | 'isConnecting'
>
export type MapStateProps = Pick<Props, 'isConnected' | 'isConnecting'>
7 changes: 0 additions & 7 deletions webapp/src/modules/features/selectors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
getIsMarketplaceLaunchPopupEnabled,
getIsSmartWearablesFTUEnabled,
isLoadingFeatureFlags,
getIsAuthDappEnabled,
getIsClaimingNamesWithFiatEnabled,
getIsEnsAddressEnabled
} from './selectors'
Expand Down Expand Up @@ -159,12 +158,6 @@ const waitForInitialLoadingSelectors = [
feature: FeatureName.EMOTES_V2_FTU,
selector: getIsEmotesV2FTUEnabled
},
{
name: 'auth-dapp',
feature: FeatureName.AUTH_DAPP,
selector: getIsAuthDappEnabled,
applicationName: ApplicationName.DAPPS
},
{
name: 'claim-name-with-fiat',
feature: FeatureName.CLAIM_NAMES_WITH_FIAT,
Expand Down
11 changes: 0 additions & 11 deletions webapp/src/modules/features/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,6 @@ export const getIsMarketplaceServerEnabled = (state: RootState) => {
return false
}

export const getIsAuthDappEnabled = (state: RootState) => {
if (hasLoadedInitialFlags(state)) {
return getIsFeatureEnabled(
state,
ApplicationName.DAPPS,
FeatureName.AUTH_DAPP
)
}
return false
}

export const getIsClaimingNamesWithFiatEnabled = (state: RootState) => {
if (hasLoadedInitialFlags(state)) {
return getIsFeatureEnabled(
Expand Down
119 changes: 34 additions & 85 deletions webapp/src/modules/identity/sagas.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expectSaga } from 'redux-saga-test-plan'
import { call, select } from 'redux-saga/effects'
import { call } from 'redux-saga/effects'
import { Wallet } from 'decentraland-dapps/dist/modules/wallet/types'
import {
connectWalletSuccess,
Expand All @@ -10,8 +10,7 @@ import {
localStorageGetIdentity
} from '@dcl/single-sign-on-client'
import { identitySaga, setAuxAddress } from './sagas'
import { generateIdentityRequest, generateIdentitySuccess } from './actions'
import { getIsAuthDappEnabled } from '../features/selectors'
import { generateIdentitySuccess } from './actions'
import { AuthIdentity } from '@dcl/crypto'

jest.mock('@dcl/single-sign-on-client', () => {
Expand All @@ -38,74 +37,38 @@ describe('when handling the wallet connection success', () => {
} as Wallet
})

describe('and the auth dapp is enabled', () => {
describe("and there's no identity", () => {
beforeEach(() => {
windowLocation = window.location
delete (window as any).location
window.location = ({
replace: jest.fn()
} as any) as Location
})
afterEach(() => {
window.location = windowLocation
})
it('should redirect to auth dapp', async () => {
await expectSaga(identitySaga)
.provide([
[call(localStorageGetIdentity, wallet.address), null],
[select(getIsAuthDappEnabled), true]
])
.dispatch(connectWalletSuccess(wallet))
.run({ silenceTimeout: true })
expect(window.location.replace).toHaveBeenCalled()
})
describe("and there's no identity", () => {
beforeEach(() => {
windowLocation = window.location
delete (window as any).location
window.location = ({
replace: jest.fn()
} as any) as Location
})

describe("and there's an identity", () => {
let identity: AuthIdentity

beforeEach(() => {
identity = {} as any
;(localStorageGetIdentity as jest.Mock).mockReturnValue(identity)
})
it('should put an action to store the identity', () => {
return expectSaga(identitySaga)
.provide([[select(getIsAuthDappEnabled), true]])
.put(generateIdentitySuccess(wallet.address, identity))
.dispatch(connectWalletSuccess(wallet))
.run({ silenceTimeout: true })
})
afterEach(() => {
window.location = windowLocation
})
})

describe('and the auth dapp is not enabled', () => {
describe("and there's no identity", () => {
it('should put an action to generate the identity', () => {
return expectSaga(identitySaga)
.provide([
[call(localStorageGetIdentity, wallet.address), null],
[select(getIsAuthDappEnabled), false]
])
.put(generateIdentityRequest(wallet.address))
.dispatch(connectWalletSuccess(wallet))
.run({ silenceTimeout: true })
})
it('should redirect to auth dapp', async () => {
await expectSaga(identitySaga)
.provide([[call(localStorageGetIdentity, wallet.address), null]])
.dispatch(connectWalletSuccess(wallet))
.run({ silenceTimeout: true })
expect(window.location.replace).toHaveBeenCalled()
})
})

describe("and there's an identity", () => {
it('should put an action to store the identity', () => {
const identity = {} as any
describe("and there's an identity", () => {
let identity: AuthIdentity

return expectSaga(identitySaga)
.provide([
[call(localStorageGetIdentity, wallet.address), identity],
[select(getIsAuthDappEnabled), false]
])
.put(generateIdentitySuccess(wallet.address, identity))
.dispatch(connectWalletSuccess(wallet))
.run({ silenceTimeout: true })
})
beforeEach(() => {
identity = {} as any
;(localStorageGetIdentity as jest.Mock).mockReturnValue(identity)
})
it('should put an action to store the identity', () => {
return expectSaga(identitySaga)
.put(generateIdentitySuccess(wallet.address, identity))
.dispatch(connectWalletSuccess(wallet))
.run({ silenceTimeout: true })
})
})
})
Expand All @@ -118,26 +81,12 @@ describe('when handling the disconnect', () => {
setAuxAddress(address)
})

describe('and the auth dapp is enabled', () => {
it('should call the sso client to clear the identity in the local storage', async () => {
await expectSaga(identitySaga)
.provide([[select(getIsAuthDappEnabled), true]])
.dispatch(disconnectWallet())
.run({ silenceTimeout: true })

expect(localStorageClearIdentity).toHaveBeenCalledWith(address)
})
})

describe('and the auth dapp is not enabled', () => {
it('should call the sso client to clear the identity', async () => {
await expectSaga(identitySaga)
.provide([[select(getIsAuthDappEnabled), false]])
.dispatch(disconnectWallet())
.run({ silenceTimeout: true })
it('should call the sso client to clear the identity in the local storage', async () => {
await expectSaga(identitySaga)
.dispatch(disconnectWallet())
.run({ silenceTimeout: true })

expect(localStorageClearIdentity).toHaveBeenCalledWith(address)
})
expect(localStorageClearIdentity).toHaveBeenCalledWith(address)
})
})

Expand Down
46 changes: 10 additions & 36 deletions webapp/src/modules/identity/sagas.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { takeLatest, put, call, select } from 'redux-saga/effects'
import { takeLatest, put, call } from 'redux-saga/effects'
import { ethers } from 'ethers'
import { Authenticator, AuthIdentity } from '@dcl/crypto'
import {
Expand All @@ -15,14 +15,12 @@ import {
import { ConnectWalletSuccessAction } from 'decentraland-dapps/dist/modules/wallet/actions'
import { isErrorWithMessage } from '../../lib/error'
import { config } from '../../config'
import { getIsAuthDappEnabled } from '../features/selectors'
import { getEth } from '../wallet/utils'

import {
GENERATE_IDENTITY_REQUEST,
GenerateIdentityRequestAction,
generateIdentityFailure,
generateIdentityRequest,
generateIdentitySuccess
} from './actions'
import { IDENTITY_EXPIRATION_IN_MINUTES } from './utils'
Expand Down Expand Up @@ -82,45 +80,21 @@ function* handleConnectWalletSuccess(action: ConnectWalletSuccessAction) {

yield call(setAuxAddress, address)

const isAuthDappEnabled: boolean = yield select(getIsAuthDappEnabled)

if (isAuthDappEnabled) {
const identity: AuthIdentity | null = localStorageGetIdentity(address)
if (identity) {
yield put(generateIdentitySuccess(address, identity))
} else {
window.location.replace(
`${config.get('AUTH_URL')}/login?redirectTo=${encodeURIComponent(
window.location.href
)}`
)
}
return
}

// Obtains the identity from the SSO iframe.
const identity: AuthIdentity | null = yield call(
localStorageGetIdentity,
address
)
const identity: AuthIdentity | null = 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.
if (!identity) {
yield put(generateIdentityRequest(address))
} else {
if (identity) {
yield put(generateIdentitySuccess(address, identity))
} else {
window.location.replace(
`${config.get('AUTH_URL')}/login?redirectTo=${encodeURIComponent(
window.location.href
)}`
)
}
}

function* handleDisconnect(_action: DisconnectWalletAction) {
if (auxAddress) {
const isAuthDappEnabled: boolean = yield select(getIsAuthDappEnabled)
if (isAuthDappEnabled) {
localStorageClearIdentity(auxAddress)
} else {
// Clears the identity from the SSO iframe when the user disconnects the wallet.
yield call(localStorageClearIdentity, auxAddress)
}
localStorageClearIdentity(auxAddress)
}
}

0 comments on commit 3b0bfb0

Please sign in to comment.