From 6e36983cc9a0c1a64b683f6d6580c1cf1aff8297 Mon Sep 17 00:00:00 2001 From: Raveesh <148246565+raveesh146@users.noreply.github.com> Date: Wed, 2 Jul 2025 23:49:49 +0530 Subject: [PATCH 1/2] Integrate Privy authentication --- app/_layout.tsx | 13 +++++++---- app/auth.tsx | 56 ++++++++++++++++++++++------------------------- package-lock.json | 12 +++++++++- package.json | 3 ++- 4 files changed, 48 insertions(+), 36 deletions(-) diff --git a/app/_layout.tsx b/app/_layout.tsx index 19ff888..f0b0667 100644 --- a/app/_layout.tsx +++ b/app/_layout.tsx @@ -1,12 +1,17 @@ import { Stack } from "expo-router"; import { StatusBar } from "expo-status-bar"; import { SafeAreaView } from "react-native-safe-area-context"; +import { PrivyProvider } from '@privy-io/react-auth'; + +const PRIVY_APP_ID = process.env.EXPO_PUBLIC_PRIVY_APP_ID || ''; export default function RootLayout() { return ( - - - - + + + + + + ); } diff --git a/app/auth.tsx b/app/auth.tsx index 70c42ce..6254395 100644 --- a/app/auth.tsx +++ b/app/auth.tsx @@ -1,6 +1,6 @@ import { Ionicons } from '@expo/vector-icons'; import { useRouter } from 'expo-router'; -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { ActivityIndicator, Alert, @@ -12,51 +12,47 @@ import { View } from 'react-native'; import { SafeAreaView } from 'react-native-safe-area-context'; +import { usePrivy } from '@privy-io/react-auth'; export default function AuthScreen() { const router = useRouter(); - const [authMethod, setAuthMethod] = useState('email'); // 'email' or 'wallet' + const { login, ready, authenticated } = usePrivy(); + const [authMethod, setAuthMethod] = useState<'email' | 'wallet'>('email'); const [email, setEmail] = useState(''); const [loading, setLoading] = useState(false); - - console.log('AuthScreen rendering...'); // Debug log + + useEffect(() => { + if (ready && authenticated) { + router.push('/home'); + } + }, [ready, authenticated]); const handleEmailAuth = async () => { if (!email.trim() || !email.includes('@')) { Alert.alert('Invalid Email', 'Please enter a valid email address'); return; } - + setLoading(true); - + try { - // In a real app, we would use Privy SDK to authenticate - // For demo purposes, we'll simulate authentication with a timeout - setTimeout(() => { - setLoading(false); - // Navigate to the main app - router.push('/home'); - }, 1500); + await login(); } catch (error) { - setLoading(false); Alert.alert('Authentication Error', 'Failed to authenticate. Please try again.'); + } finally { + setLoading(false); } }; - const handleWalletAuth = async (walletType: string) => { + const handleWalletAuth = async () => { setLoading(true); - + try { - // In a real app, we would use Privy SDK or WalletConnect for mobile - // For demo purposes, we'll simulate wallet connection with a timeout - setTimeout(() => { - setLoading(false); - // Navigate to the main app - router.push('/home'); - }, 1500); + await login(); } catch (error) { - setLoading(false); Alert.alert('Wallet Connection Error', 'Failed to connect wallet. Please try again.'); + } finally { + setLoading(false); } }; @@ -138,9 +134,9 @@ export default function AuthScreen() { - handleWalletAuth('metamask')} + onPress={handleWalletAuth} disabled={loading} > MetaMask - handleWalletAuth('walletconnect')} + onPress={handleWalletAuth} disabled={loading} > WalletConnect - handleWalletAuth('coinbase')} + onPress={handleWalletAuth} disabled={loading} > =18" + } + }, "node_modules/react-native/node_modules/@react-native/virtualized-lists": { "version": "0.79.4", "resolved": "https://registry.npmjs.org/@react-native/virtualized-lists/-/virtualized-lists-0.79.4.tgz", diff --git a/package.json b/package.json index a66ff6b..48701ac 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,8 @@ "react-native-safe-area-context": "5.4.0", "react-native-screens": "~4.11.1", "react-native-web": "~0.20.0", - "react-native-webview": "13.13.5" + "react-native-webview": "13.13.5", + "@privy-io/react-auth": "^0.13.2" }, "devDependencies": { "@babel/core": "^7.25.2", From 9d4e9465a090cc6a6f40e5c958904606967277e5 Mon Sep 17 00:00:00 2001 From: Raveesh <148246565+raveesh146@users.noreply.github.com> Date: Wed, 2 Jul 2025 23:59:51 +0530 Subject: [PATCH 2/2] fix lint script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 48701ac..0e094fb 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "android": "expo start --android", "ios": "expo start --ios", "web": "expo start --web", - "lint": "expo lint" + "lint": "npx expo lint" }, "dependencies": { "@expo/vector-icons": "^14.1.0",