Files
pwap/mobile/App.tsx
T
Claude ada1883b52 feat(mobile): implement real Supabase authentication
Replace mock authentication with real Supabase integration:

**New Files:**
- mobile/src/lib/supabase.ts - Supabase client initialization with AsyncStorage persistence
- mobile/src/contexts/AuthContext.tsx - Complete authentication context with session management

**Updated Files:**
- mobile/src/screens/SignInScreen.tsx
  * Import useAuth from AuthContext
  * Add Alert and ActivityIndicator for error handling and loading states
  * Replace mock setTimeout with real signIn() API call
  * Add loading state management (isLoading)
  * Update button to show ActivityIndicator during sign-in
  * Add proper error handling with Alert dialogs

- mobile/src/screens/SignUpScreen.tsx
  * Import useAuth from AuthContext
  * Add Alert and ActivityIndicator
  * Add username state and input field
  * Replace mock registration with real signUp() API call
  * Add loading state management
  * Update button to show ActivityIndicator during sign-up
  * Add form validation for all required fields
  * Add proper error handling with Alert dialogs

- mobile/App.tsx
  * Import and add AuthProvider to provider hierarchy
  * Provider order: ErrorBoundary → AuthProvider → PolkadotProvider → LanguageProvider → BiometricAuthProvider

**Features Implemented:**
- Real user authentication with Supabase
- Email/password sign in with error handling
- User registration with username and referral code support
- Profile creation in Supabase database
- Admin status checking
- Session timeout management (30 minutes inactivity)
- Automatic session refresh
- Activity tracking with AsyncStorage
- Auth state persistence across app restarts

**Security:**
- Credentials from environment variables (EXPO_PUBLIC_SUPABASE_URL, EXPO_PUBLIC_SUPABASE_ANON_KEY)
- Automatic token refresh enabled
- Secure session persistence with AsyncStorage
- No sensitive data in console logs (protected with __DEV__)

This completes P0 authentication implementation for mobile app.
Production ready authentication matching web implementation.
2025-11-21 22:23:35 +00:00

65 lines
1.8 KiB
TypeScript

import React, { useEffect, useState } from 'react';
import { View, ActivityIndicator, StyleSheet } from 'react-native';
import { StatusBar } from 'expo-status-bar';
import { initializeI18n } from './src/i18n';
import { ErrorBoundary } from './src/components/ErrorBoundary';
import { LanguageProvider } from './src/contexts/LanguageContext';
import { AuthProvider } from './src/contexts/AuthContext';
import { PolkadotProvider } from './src/contexts/PolkadotContext';
import { BiometricAuthProvider } from './src/contexts/BiometricAuthContext';
import AppNavigator from './src/navigation/AppNavigator';
import { KurdistanColors } from './src/theme/colors';
export default function App() {
const [isI18nInitialized, setIsI18nInitialized] = useState(false);
useEffect(() => {
// Initialize i18n on app start
const initApp = async () => {
try {
await initializeI18n();
setIsI18nInitialized(true);
} catch (error) {
console.error('Failed to initialize i18n:', error);
// Fallback: Still show app but with default language
setIsI18nInitialized(true);
}
};
initApp();
}, []);
if (!isI18nInitialized) {
return (
<View style={styles.loadingContainer}>
<ActivityIndicator size="large" color={KurdistanColors.kesk} />
</View>
);
}
return (
<ErrorBoundary>
<AuthProvider>
<PolkadotProvider>
<LanguageProvider>
<BiometricAuthProvider>
<StatusBar style="auto" />
<AppNavigator />
</BiometricAuthProvider>
</LanguageProvider>
</PolkadotProvider>
</AuthProvider>
</ErrorBoundary>
);
}
const styles = StyleSheet.create({
loadingContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: KurdistanColors.spi,
},
});