Skip to content

Commit

Permalink
fix: Remove functions that consume the iframe
Browse files Browse the repository at this point in the history
  • Loading branch information
fzavalia committed Feb 7, 2024
1 parent 653f06c commit 6d03a28
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/lib/api/auth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Authenticator } from '@dcl/crypto'
import { getIdentity } from '@dcl/single-sign-on-client'
import { localStorageGetIdentity } from '@dcl/single-sign-on-client'
import { getAddress } from 'decentraland-dapps/dist/modules/wallet/selectors'
import { RootStore } from 'modules/common/types'

Expand All @@ -12,13 +12,13 @@ export class Authorization {
this.store = store
}

async createAuthHeaders(method = 'get', path = '') {
createAuthHeaders(method = 'get', path = '') {
const headers: Record<string, string> = {}
const state = this.store.getState()
const address = getAddress(state)

if (address) {
const identity = await getIdentity(address)
const identity = localStorageGetIdentity(address)

if (identity) {
const endpoint = (method + ':' + path).toLowerCase()
Expand Down
6 changes: 3 additions & 3 deletions src/lib/api/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ export class BuilderAPI extends BaseAPI {
headers = { ...config.headers }
}
}
const authHeaders = await this.authorization.createAuthHeaders(method, path)
const authHeaders = this.authorization.createAuthHeaders(method, path)
headers = {
...headers,
...authHeaders
Expand Down Expand Up @@ -623,7 +623,7 @@ export class BuilderAPI extends BaseAPI {
}

async fetchMain(projectId: string): Promise<Blob> {
const request = async (path: string) => fetch(this.url + path, { headers: await this.authorization.createAuthHeaders('get', path) })
const request = async (path: string) => fetch(this.url + path, { headers: this.authorization.createAuthHeaders('get', path) })
const about: { configurations: { scenesUrn: string[] } } = await request(`/projects/${projectId}/about`).then(resp => resp.json())
const urn = about.configurations.scenesUrn[0]
const hash = urn.split('urn:decentraland:entity:').pop()!.split('?')[0]
Expand All @@ -635,7 +635,7 @@ export class BuilderAPI extends BaseAPI {

async fetchCrdt(projectId: string): Promise<Blob> {
const path = `/projects/${projectId}/crdt`
const headers = await this.authorization.createAuthHeaders('get', path)
const headers = this.authorization.createAuthHeaders('get', path)
const response = await fetch(this.url + path, { headers })
const blob = await response.blob()
return blob
Expand Down
13 changes: 6 additions & 7 deletions src/modules/identity/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ethers } from 'ethers'
import { replace, getLocation } from 'connected-react-router'
import { Authenticator, AuthIdentity } from '@dcl/crypto'
import { ProviderType } from '@dcl/schemas'
import { getIdentity, storeIdentity, clearIdentity, localStorageGetIdentity } from '@dcl/single-sign-on-client'
import { localStorageClearIdentity, localStorageGetIdentity, localStorageStoreIdentity } from '@dcl/single-sign-on-client'
import { getData as getWallet, isConnected, getAddress } from 'decentraland-dapps/dist/modules/wallet/selectors'
import { Wallet } from 'decentraland-dapps/dist/modules/wallet/types'
import { config } from 'config'
Expand Down Expand Up @@ -87,7 +87,7 @@ function* handleGenerateIdentityRequest(action: GenerateIdentityRequestAction) {
signer.signMessage(message)
)

yield call(storeIdentity, address, identity)
yield call(localStorageStoreIdentity, address, identity)

yield put(generateIdentitySuccess(address, identity))
} catch (error) {
Expand Down Expand Up @@ -133,7 +133,7 @@ function* handleLogin(action: LoginRequestAction) {
}

const address: string = yield select(getAddress)
const identity: AuthIdentity | null = yield call(getIdentity, address)
const identity: AuthIdentity | null = yield call(localStorageGetIdentity, address)

if (identity) {
yield put(generateIdentitySuccess(address, identity))
Expand Down Expand Up @@ -168,8 +168,7 @@ function* handleLogout(_action: LogoutAction) {
if (address) {
yield put(disconnectWallet())
yield put(destroyIdentity(address))
// Clear the identity from the SSO iframe. Doing so will log you out of all DCL applications (That use SSO).
yield call(clearIdentity, address)
yield call(localStorageClearIdentity, address)
}
}

Expand All @@ -191,7 +190,7 @@ function* handleConnectWalletSuccess(action: ConnectWalletSuccessAction) {
}

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

// If an identity is found, store it and proceed with the login so the state acknowledges that the user is connected.
// If not, proceed with the login in order to retrieve user's signature.
Expand Down Expand Up @@ -221,7 +220,7 @@ function* handleChangeAccount(action: ChangeAccountAction) {
}

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

// If an identity is found, store it and proceed with the login so the state acknowledges that the user is connected.
// If not, proceed with the login in order to retrieve user's signature.
Expand Down

0 comments on commit 6d03a28

Please sign in to comment.