// App.auth.tsx /** * AUTH STARTER TEMPLATE * * Authentication-enabled app with login/register flow and basic dashboard. * Good starting point for apps requiring user authentication. * * INCLUDED MODULES: * - Authentication flow (login/register) * - Basic dashboard with navigation * - User profile management * - (At the moment it has no real module dependancies – but I'd like to connect to main-navigator in a near future) * * FEATURES: * - Complete auth flow with form validation * - User state management * - 3-screen dashboard (Home, Profile, Settings) * - Mock API simulation * - Session management * * DEPENDENCIES: * - React Native core components only * * USE CASE: Apps with user accounts, personalized content, secure features */ import React, { useState } from 'react'; import { SafeAreaView, StyleSheet, View, Text, TouchableOpacity, ScrollView, TextInput, ActivityIndicator, Alert } from 'react-native'; import packageJson from './package.json'; // Types interface User { id: string; name: string; email: string; } type AuthScreen = 'login' | 'register'; type AppScreen = 'home' | 'profile' | 'settings'; // Basic Card component const BasicCard: React.FC<{ title: string; content: string; onPress?: () => void }> = ({ title, content, onPress }) => ( {title} {content} {onPress && } ); export default function App() { const appVersion = packageJson.version; const appName = packageJson.name; // Auth state const [user, setUser] = useState(null); const [authScreen, setAuthScreen] = useState('login'); const [loading, setLoading] = useState(false); // App state const [currentScreen, setCurrentScreen] = useState('home'); // Form state const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [name, setName] = useState(''); console.log(`\n\n\n\n==================================\n\n${appName} (Auth) started: version ${appVersion}\n\n==================================`); // Auth functions const handleLogin = async () => { if (!email || !password) { Alert.alert('Error', 'Please fill in all fields'); return; } setLoading(true); // Simulate API call setTimeout(() => { const mockUser: User = { id: '1', name: name || 'John Doe', email: email, }; setUser(mockUser); setLoading(false); Alert.alert('Success', 'Logged in successfully!'); }, 1500); }; const handleRegister = async () => { if (!name || !email || !password) { Alert.alert('Error', 'Please fill in all fields'); return; } setLoading(true); // Simulate API call setTimeout(() => { const mockUser: User = { id: '2', name: name, email: email, }; setUser(mockUser); setLoading(false); Alert.alert('Success', 'Account created successfully!'); }, 1500); }; const handleLogout = () => { setUser(null); setEmail(''); setPassword(''); setName(''); Alert.alert('Success', 'Logged out successfully!'); }; // Auth screens const renderLogin = () => ( Welcome Back Sign in to your account {loading ? ( ) : ( Sign In )} setAuthScreen('register')} > Don't have an account? Sign Up ); const renderRegister = () => ( Create Account Join us today {loading ? ( ) : ( Sign Up )} setAuthScreen('login')} > Already have an account? Sign In ); // App screens const renderHome = () => ( Welcome, {user?.name}! Auth Starter Template Alert.alert('Info', 'Dashboard feature coming soon!')} /> Alert.alert('Info', 'Quick actions coming soon!')} /> Alert.alert('Info', 'Activity feature coming soon!')} /> ); const renderProfile = () => ( Profile Manage your account Alert.alert('Info', 'Account settings coming soon!')} /> Logout ); const renderSettings = () => ( Settings App preferences Alert.alert('Info', 'Notification settings coming soon!')} /> Alert.alert('Info', 'Privacy settings coming soon!')} /> ); const renderAppContent = () => { switch (currentScreen) { case 'home': return renderHome(); case 'profile': return renderProfile(); case 'settings': return renderSettings(); default: return renderHome(); } }; // Main render if (!user) { return ( {authScreen === 'login' ? renderLogin() : renderRegister()} ); } return ( {/* Header */} {appName} Logout {/* Main Content */} {renderAppContent()} {/* Bottom Navigation */} setCurrentScreen('home')} > Home setCurrentScreen('profile')} > Profile setCurrentScreen('settings')} > Settings ); } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#f5f5f5', }, // Auth styles authContainer: { flex: 1, justifyContent: 'center', }, authContent: { flex: 1, padding: 24, }, authHeader: { alignItems: 'center', marginBottom: 32, }, authTitle: { fontSize: 28, fontWeight: 'bold', color: '#333333', marginBottom: 8, }, authSubtitle: { fontSize: 16, color: '#666666', }, inputContainer: { marginBottom: 24, }, input: { backgroundColor: '#ffffff', borderRadius: 8, paddingHorizontal: 16, paddingVertical: 12, fontSize: 16, color: '#333333', marginBottom: 16, borderWidth: 1, borderColor: '#e0e0e0', }, primaryButton: { backgroundColor: '#007AFF', borderRadius: 8, paddingVertical: 16, alignItems: 'center', marginBottom: 16, }, disabledButton: { backgroundColor: '#cccccc', }, primaryButtonText: { color: 'white', fontSize: 16, fontWeight: '600', }, secondaryButton: { alignItems: 'center', }, secondaryButtonText: { color: '#007AFF', fontSize: 14, }, // App styles header: { backgroundColor: '#ffffff', paddingVertical: 16, paddingHorizontal: 20, borderBottomWidth: 1, borderBottomColor: '#e0e0e0', flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', }, headerTitle: { fontSize: 20, fontWeight: '600', color: '#333333', }, headerLogout: { paddingHorizontal: 12, paddingVertical: 6, backgroundColor: '#ff4444', borderRadius: 6, }, headerLogoutText: { color: 'white', fontSize: 14, fontWeight: '500', }, content: { flex: 1, padding: 16, }, welcomeSection: { alignItems: 'center', marginBottom: 24, }, welcomeTitle: { fontSize: 24, fontWeight: 'bold', color: '#333333', textAlign: 'center', marginBottom: 8, }, welcomeSubtitle: { fontSize: 16, color: '#666666', textAlign: 'center', }, card: { backgroundColor: '#ffffff', borderRadius: 8, padding: 16, marginBottom: 16, shadowColor: '#000', shadowOffset: { width: 0, height: 2, }, shadowOpacity: 0.1, shadowRadius: 3.84, elevation: 5, flexDirection: 'row', alignItems: 'center', }, cardTitle: { fontSize: 18, fontWeight: '600', color: '#333333', marginBottom: 8, flex: 1, }, cardContent: { fontSize: 14, color: '#666666', lineHeight: 20, flex: 1, }, cardArrow: { fontSize: 18, color: '#007AFF', marginLeft: 8, }, logoutButton: { backgroundColor: '#ff4444', borderRadius: 8, paddingVertical: 16, alignItems: 'center', marginTop: 16, }, logoutButtonText: { color: 'white', fontSize: 16, fontWeight: '600', }, bottomNav: { flexDirection: 'row', backgroundColor: '#ffffff', borderTopWidth: 1, borderTopColor: '#e0e0e0', paddingVertical: 8, }, navButton: { flex: 1, paddingVertical: 12, paddingHorizontal: 8, alignItems: 'center', }, navButtonActive: { backgroundColor: '#007AFF', marginHorizontal: 4, borderRadius: 6, }, navButtonText: { fontSize: 14, color: '#666666', fontWeight: '500', }, navButtonTextActive: { color: '#ffffff', fontWeight: '600', }, });