diff --git a/projects/TokenizeRWATemplate-frontend/src/components/Web3AuthProvider.tsx b/projects/TokenizeRWATemplate-frontend/src/components/Web3AuthProvider.tsx index 90056a5..0e7e2a2 100644 --- a/projects/TokenizeRWATemplate-frontend/src/components/Web3AuthProvider.tsx +++ b/projects/TokenizeRWATemplate-frontend/src/components/Web3AuthProvider.tsx @@ -33,34 +33,22 @@ export function Web3AuthProvider({ children }: { children: ReactNode }) { useEffect(() => { const initializeWeb3Auth = async () => { - console.log('🎯 WEB3AUTHPROVIDER: Starting initialization') - console.log('🎯 Environment variables:', { - clientId: import.meta.env.VITE_WEB3AUTH_CLIENT_ID ? 'SET' : 'MISSING', - mode: import.meta.env.MODE, - dev: import.meta.env.DEV, - }) - try { setIsLoading(true) setError(null) - console.log('🎯 Calling initWeb3Auth()...') const web3auth = await initWeb3Auth() - console.log('🎯 initWeb3Auth() returned:', web3auth) setWeb3AuthInstance(web3auth) if (web3auth.status === 'connected' && web3auth.provider) { - console.log('🎯 User already connected from previous session') setProvider(web3auth.provider) setIsConnected(true) try { const account = await getAlgorandAccount(web3auth.provider) setAlgorandAccount(account) - console.log('🎯 Algorand account derived:', account.address) } catch (err) { - console.error('🎯 Failed to derive Algorand account:', err) setError('Failed to derive Algorand account. Please reconnect.') } @@ -68,7 +56,6 @@ export function Web3AuthProvider({ children }: { children: ReactNode }) { const userInformation = await getWeb3AuthUserInfo() if (userInformation) { setUserInfo(userInformation) - console.log('🎯 User info fetched:', userInformation) } } catch (err) { console.error('🎯 Failed to fetch user info:', err) @@ -76,7 +63,6 @@ export function Web3AuthProvider({ children }: { children: ReactNode }) { } setIsInitialized(true) - console.log('🎯 WEB3AUTHPROVIDER: Initialization complete') } catch (err) { const errorMessage = err instanceof Error ? err.message : 'Failed to initialize Web3Auth' console.error('🎯 WEB3AUTHPROVIDER: Initialization error:', err) @@ -91,7 +77,6 @@ export function Web3AuthProvider({ children }: { children: ReactNode }) { }, []) const login = async () => { - console.log('🎯 LOGIN: Called') if (!web3AuthInstance) { console.error('🎯 LOGIN: Web3Auth not initialized') @@ -109,9 +94,7 @@ export function Web3AuthProvider({ children }: { children: ReactNode }) { setIsLoading(true) setError(null) - console.log('🎯 LOGIN: Calling web3AuthInstance.connect()...') const web3authProvider = await web3AuthInstance.connect() - console.log('🎯 LOGIN: connect() returned:', web3authProvider ? 'PROVIDER' : 'NULL') if (!web3authProvider) { throw new Error('Failed to connect Web3Auth provider') @@ -121,28 +104,22 @@ export function Web3AuthProvider({ children }: { children: ReactNode }) { setIsConnected(true) try { - console.log('🎯 LOGIN: Deriving Algorand account...') const account = await getAlgorandAccount(web3authProvider) setAlgorandAccount(account) - console.log('🎯 LOGIN: Successfully derived Algorand account:', account.address) } catch (err) { const errorMessage = err instanceof Error ? err.message : 'Failed to derive Algorand account' setError(errorMessage) - console.error('🎯 LOGIN: Algorand account derivation error:', err) } try { - console.log('🎯 LOGIN: Fetching user info...') const userInformation = await getWeb3AuthUserInfo() if (userInformation) { setUserInfo(userInformation) - console.log('🎯 LOGIN: User info fetched') } } catch (err) { console.error('🎯 LOGIN: Failed to fetch user info:', err) } - console.log('🎯 LOGIN: Complete') } catch (err) { const errorMessage = err instanceof Error ? err.message : 'Login failed' console.error('🎯 LOGIN: Error:', err) @@ -156,8 +133,6 @@ export function Web3AuthProvider({ children }: { children: ReactNode }) { } const logout = async () => { - console.log('🎯 LOGOUT: Called') - try { setIsLoading(true) setError(null) @@ -169,7 +144,6 @@ export function Web3AuthProvider({ children }: { children: ReactNode }) { setAlgorandAccount(null) setUserInfo(null) - console.log('🎯 LOGOUT: Complete') } catch (err) { const errorMessage = err instanceof Error ? err.message : 'Logout failed' console.error('🎯 LOGOUT: Error:', err) @@ -185,12 +159,10 @@ export function Web3AuthProvider({ children }: { children: ReactNode }) { } const refreshUserInfo = async () => { - console.log('🎯 REFRESH: Called') try { const userInformation = await getWeb3AuthUserInfo() if (userInformation) { setUserInfo(userInformation) - console.log('🎯 REFRESH: User info refreshed') } } catch (err) { console.error('🎯 REFRESH: Failed:', err) diff --git a/projects/TokenizeRWATemplate-frontend/src/utils/web3auth/web3authConfig.ts b/projects/TokenizeRWATemplate-frontend/src/utils/web3auth/web3authConfig.ts index 6b2a03e..f696887 100644 --- a/projects/TokenizeRWATemplate-frontend/src/utils/web3auth/web3authConfig.ts +++ b/projects/TokenizeRWATemplate-frontend/src/utils/web3auth/web3authConfig.ts @@ -5,19 +5,12 @@ import { Web3Auth } from '@web3auth/modal' let web3authInstance: Web3Auth | null = null export async function initWeb3Auth(): Promise { - console.log('========================================') - console.log('🔧 STARTING WEB3AUTH INITIALIZATION') - console.log('========================================') if (web3authInstance) { - console.log('✅ Web3Auth already initialized, returning existing instance') return web3authInstance } const clientId = import.meta.env.VITE_WEB3AUTH_CLIENT_ID - console.log('📋 Client ID check:', clientId ? '✅ SET' : '❌ MISSING') - console.log('📋 Client ID length:', clientId?.length || 0) - console.log('📋 Client ID (first 20 chars):', clientId?.substring(0, 20) + '...') if (!clientId) { const error = new Error('VITE_WEB3AUTH_CLIENT_ID is not configured') @@ -26,7 +19,6 @@ export async function initWeb3Auth(): Promise { } try { - console.log('📦 Creating privateKeyProvider...') // Create the private key provider for Algorand const privateKeyProvider = new CommonPrivateKeyProvider({ @@ -43,9 +35,6 @@ export async function initWeb3Auth(): Promise { }, }) - console.log('✅ privateKeyProvider created') - console.log('📦 Creating Web3Auth configuration object...') - const web3AuthConfig = { clientId, web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_DEVNET, @@ -61,51 +50,27 @@ export async function initWeb3Auth(): Promise { }, } - console.log('📦 Config created with privateKeyProvider') - console.log('🏗️ Instantiating Web3Auth...') - web3authInstance = new Web3Auth(web3AuthConfig) - console.log('✅ Web3Auth instance created successfully') - console.log('📞 Calling initModal()...') - await web3authInstance.initModal() - console.log('✅ initModal() completed successfully') - console.log('📊 Web3Auth status:', web3authInstance.status) - console.log('📊 Web3Auth connected:', web3authInstance.connected) - console.log('========================================') - console.log('✅ WEB3AUTH INITIALIZATION COMPLETE') - console.log('========================================') - return web3authInstance } catch (error) { - console.error('========================================') - console.error('❌ WEB3AUTH INITIALIZATION FAILED') - console.error('========================================') - console.error('Error type:', error?.constructor?.name) - console.error('Error message:', error instanceof Error ? error.message : 'Unknown error') - console.error('Full error:', error) - console.error('Stack trace:', error instanceof Error ? error.stack : 'No stack trace') - console.error('========================================') throw error } } export function getWeb3AuthInstance(): Web3Auth | null { - console.log('🔍 getWeb3AuthInstance() called, instance:', web3authInstance ? '✅ EXISTS' : '❌ NULL') return web3authInstance } export function getWeb3AuthProvider(): IProvider | null { const provider = web3authInstance?.provider || null - console.log('🔍 getWeb3AuthProvider() called, provider:', provider ? '✅ EXISTS' : '❌ NULL') return provider } export function isWeb3AuthConnected(): boolean { const connected = web3authInstance?.status === 'connected' - console.log('🔍 isWeb3AuthConnected() called, connected:', connected) return connected } @@ -117,36 +82,27 @@ export interface Web3AuthUserInfo { } export async function getWeb3AuthUserInfo(): Promise { - console.log('🔍 getWeb3AuthUserInfo() called') - if (!web3authInstance || !isWeb3AuthConnected()) { - console.log('❌ Cannot get user info: not connected') return null } try { const userInfo = await web3authInstance.getUserInfo() - console.log('✅ User info retrieved:', userInfo) return userInfo as Web3AuthUserInfo } catch (error) { - console.error('❌ Failed to get user info:', error) return null } } export async function logoutFromWeb3Auth(): Promise { - console.log('🚪 logoutFromWeb3Auth() called') if (!web3authInstance) { - console.log('⚠️ No instance to logout from') return } try { await web3authInstance.logout() - console.log('✅ Logged out successfully') } catch (error) { - console.error('❌ Logout failed:', error) throw error } }