Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
17 changes: 2 additions & 15 deletions src/components/Pages/RequestPage/RequestPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import { getContract, sendMetaTransaction, ContractName } from 'decentraland-tra
import { useNavigateWithSearchParams } from '../../../hooks/navigation'
import { useTargetConfig } from '../../../hooks/targetConfig'
import { useAnalytics } from '../../../hooks/useAnalytics'
import { useDisabledCatalysts } from '../../../hooks/useDisabledCatalysts'
import { getAnalytics } from '../../../modules/analytics/segment'
import { ClickEvents, TrackingEvents } from '../../../modules/analytics/types'
import { config } from '../../../modules/config'
import { fetchProfile, fetchProfileWithConsistencyCheck, redeployExistingProfile } from '../../../modules/profile'
import { fetchProfile } from '../../../modules/profile'
import {
createAuthServerHttpClient,
RecoverResponse,
Expand Down Expand Up @@ -140,7 +139,6 @@ export const RequestPage = () => {
const authServerClient = useRef(createAuthServerHttpClient())
const isDeepLinkFlow = searchParams.get('flow') === 'deeplink'
const flowParam = isDeepLinkFlow ? '&flow=deeplink' : ''
const disabledCatalysts = useDisabledCatalysts()
// Goes to the login page where the user will have to connect a wallet.
// Preserve loginMethod from current URL if present for auto-login functionality
const loginMethodParam = searchParams.get('loginMethod')
Expand Down Expand Up @@ -192,17 +190,6 @@ export const RequestPage = () => {
const timeTheSiteStartedLoading = Date.now()
browserProvider.current = new ethers.BrowserProvider(provider)

const consistencyResult = await fetchProfileWithConsistencyCheck(account, disabledCatalysts)
console.log('Loading request - Consistency result', consistencyResult)
if (!consistencyResult.isConsistent && consistencyResult.profile && identity) {
try {
await redeployExistingProfile(consistencyResult.profile, account, identity, disabledCatalysts)
} catch (error) {
console.warn('Profile redeployment failed, falling back to login page:', error)
toLoginPage()
}
}

const profile = await fetchProfile(account)

// `alternative` has its own set up
Expand Down Expand Up @@ -342,7 +329,7 @@ export const RequestPage = () => {
clearTimeout(timeoutRef.current)
clearTimeout(signTimeoutRef.current)
}
}, [toLoginPage, toSetupPage, account, provider, providerType, isConnecting, initializedFlags, identity])
}, [toLoginPage, toSetupPage, account, provider, providerType, isConnecting, initializedFlags])

useEffect(() => {
// The timeout is only necessary on the verify sign in and wallet interaction views.
Expand Down
84 changes: 7 additions & 77 deletions src/hooks/useAuthFlow.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
import { useCallback, useContext } from 'react'
import type { Profile } from 'dcl-catalyst-client/dist/client/specs/catalyst.schemas'
import { AuthIdentity } from '@dcl/crypto'
import { ProviderType } from '@dcl/schemas'
import { connection } from 'decentraland-connect'
import { FeatureFlagsContext, FeatureFlagsKeys, OnboardingFlowVariant } from '../components/FeatureFlagsProvider'
import { config } from '../modules/config'
import { fetchProfileWithConsistencyCheck, redeployExistingProfile, redeployExistingProfileWithContentServerData } from '../modules/profile'
import { useCurrentConnectionData } from '../shared/connection/hook'
import { createFetcher } from '../shared/fetcher'
import { fetchProfile } from '../modules/profile'
import { locations } from '../shared/locations'
import { isProfileComplete } from '../shared/profile'
import { checkWebGpuSupport } from '../shared/utils/webgpu'
import { useNavigateWithSearchParams } from './navigation'
import { useAfterLoginRedirection } from './redirection'
import { useTargetConfig } from './targetConfig'
import { useAnalytics } from './useAnalytics'
import { useDisabledCatalysts } from './useDisabledCatalysts'

/**
* Custom hook that manages authentication flow logic including Magic connection
* and profile validation with redirects based on profile state and feature flags.
*
* @returns {{
* checkProfileAndRedirect: (account: string, referrer: string | null, redirect: () => void, providedIdentity?: AuthIdentity | null) => Promise<void>,
* checkProfileAndRedirect: (account: string, referrer: string | null, redirect: () => void) => Promise<void>,
* connectToMagic: () => Promise<import('decentraland-connect').ConnectionResponse | undefined>,
* isInitialized: boolean
* }} Authentication flow utilities and initialization status
Expand All @@ -33,8 +27,6 @@ export const useAuthFlow = () => {
const { flags, variants, initialized: flagInitialized } = useContext(FeatureFlagsContext)

const [targetConfig] = useTargetConfig()
const { identity } = useCurrentConnectionData()
const disabledCatalysts = useDisabledCatalysts()
const { trackWebGPUSupportCheck } = useAnalytics()

/**
Expand All @@ -54,79 +46,25 @@ export const useAuthFlow = () => {
}, [flags[FeatureFlagsKeys.MAGIC_TEST], flagInitialized])

/**
* Checks profile consistency across catalysts and redirects based on profile state.
* Handles profile redeployment if inconsistent, and navigates to setup/avatar setup
* flows based on feature flags and WebGPU support.
* Checks if profile exists and redirects based on profile state.
* Navigates to setup/avatar setup flows based on feature flags and WebGPU support.
*
* @param {string} account - The user's account address
* @param {string | null} referrer - The referrer URL string or null
* @param {() => void} redirect - Callback function to execute for successful redirect
* @param {AuthIdentity | null} [providedIdentity] - Optional authentication identity to use for redeployment.
* Falls back to hook identity if not provided.
* @returns {Promise<void>} A promise that resolves after the navigation or redirect completes
*/
const checkProfileAndRedirect = useCallback(
async (account: string, referrer: string | null, redirect: () => void, providedIdentity: AuthIdentity | null = null) => {
async (account: string, referrer: string | null, redirect: () => void) => {
if (!flagInitialized) {
return undefined
}

if (targetConfig && !targetConfig.skipSetup && account) {
// Check profile consistency across all catalysts
const fetcherWithTimeout = createFetcher({
timeout: Number(config.get('PROFILE_CONSISTENCY_CHECK_TIMEOUT')) ?? 10000
})

const consistencyResult = await fetchProfileWithConsistencyCheck(account, disabledCatalysts, fetcherWithTimeout)
const profile = await fetchProfile(account)

// Check A/B testing new onboarding flow
const isFlowV2OnboardingFlowEnabled = variants[FeatureFlagsKeys.ONBOARDING_FLOW]?.name === OnboardingFlowVariant.V2

// If profile is not consistent across catalysts, try to redeploy if we have a valid entity
if (!consistencyResult.isConsistent) {
// Use provided identity first, then fall back to hook identity
const userIdentity = providedIdentity ?? identity

// If we have a valid entity and user identity, attempt redeployment
if (consistencyResult.profile && consistencyResult.profileFetchedFrom && userIdentity) {
try {
await redeployExistingProfile(consistencyResult.profile, account, userIdentity, disabledCatalysts, fetcherWithTimeout)
// If redeployment succeeds, continue with the login flow
return redirect()
} catch (error) {
console.warn('Profile redeployment failed, attempting to redeploy with content server data:', error)
// If redeployment with lamb2 profile fails, try to redeploy with content server data
try {
await redeployExistingProfileWithContentServerData(
consistencyResult.profileFetchedFrom,
account,
userIdentity,
disabledCatalysts,
fetcherWithTimeout
)
// If redeployment succeeds, continue with the login flow
return redirect()
} catch (error) {
console.warn('Profile redeployment failed, falling back to onboarding:', error)
// Fall through to onboarding flow
}
}
}

// Fallback to onboarding flow (original behavior)
const hasWebGPU = await checkWebGpuSupport()
trackWebGPUSupportCheck({ supported: hasWebGPU })
const isAvatarSetupFlowAllowed = isFlowV2OnboardingFlowEnabled && hasWebGPU

if (isAvatarSetupFlowAllowed) {
return navigate(locations.avatarSetup(redirectTo, referrer))
} else {
return navigate(locations.setup(redirectTo, referrer))
}
}

// If consistent, check if profile exists and is complete
const profile: Profile | undefined = consistencyResult.profile
const hasWebGPU = await checkWebGpuSupport()
trackWebGPUSupportCheck({ supported: hasWebGPU })
const isAvatarSetupFlowAllowed = isFlowV2OnboardingFlowEnabled && hasWebGPU
Expand All @@ -141,15 +79,7 @@ export const useAuthFlow = () => {

redirect()
},
[
targetConfig?.skipSetup,
variants[FeatureFlagsKeys.ONBOARDING_FLOW],
navigate,
redirectTo,
flagInitialized,
identity,
disabledCatalysts
]
[targetConfig?.skipSetup, variants[FeatureFlagsKeys.ONBOARDING_FLOW], navigate, redirectTo, flagInitialized]
)

return {
Expand Down
23 changes: 0 additions & 23 deletions src/hooks/useDisabledCatalysts.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/modules/config/env/dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"DOWNLOAD_URL": "https://decentraland.zone/download",
"META_TRANSACTION_SERVER_URL": "https://transactions-api.decentraland.zone",
"PLACES_API_URL": "https://places.decentraland.zone",
"PROFILE_CONSISTENCY_CHECK_TIMEOUT": "10000",
"EVENTS_NOTIFIER_URL": "https://events-notifier.decentraland.zone",
"THIRDWEB_CLIENT_ID": "8d056704cd974d011e0c4c51dadb841e"
"THIRDWEB_CLIENT_ID": "8d056704cd974d011e0c4c51dadb841e",
"ASSET_BUNDLE_REGISTRY_URL": "https://asset-bundle-registry.decentraland.zone"
}
4 changes: 2 additions & 2 deletions src/modules/config/env/prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"DOWNLOAD_URL": "https://decentraland.org/download",
"META_TRANSACTION_SERVER_URL": "https://transactions-api.decentraland.org",
"PLACES_API_URL": "https://places.decentraland.org",
"PROFILE_CONSISTENCY_CHECK_TIMEOUT": "10000",
"EVENTS_NOTIFIER_URL": "https://events-notifier.decentraland.org",
"THIRDWEB_CLIENT_ID": "8d056704cd974d011e0c4c51dadb841e"
"THIRDWEB_CLIENT_ID": "8d056704cd974d011e0c4c51dadb841e",
"ASSET_BUNDLE_REGISTRY_URL": "https://asset-bundle-registry.decentraland.org"
}
4 changes: 2 additions & 2 deletions src/modules/config/env/stg.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"DOWNLOAD_URL": "https://decentraland.zone/download",
"META_TRANSACTION_SERVER_URL": "https://transactions-api.decentraland.today",
"PLACES_API_URL": "https://places.decentraland.today",
"PROFILE_CONSISTENCY_CHECK_TIMEOUT": "10000",
"EVENTS_NOTIFIER_URL": "https://events-notifier.decentraland.zone",
"THIRDWEB_CLIENT_ID": "8d056704cd974d011e0c4c51dadb841e"
"THIRDWEB_CLIENT_ID": "8d056704cd974d011e0c4c51dadb841e",
"ASSET_BUNDLE_REGISTRY_URL": "https://asset-bundle-registry.decentraland.org"
}
Loading