A comprehensive React Native authentication template with Firebase, featuring modern UI components, secure token management, and rate limiting.
- 🔐 Firebase Authentication - Complete email/password authentication
- 📱 Modern UI - Beautiful, accessible components with dark mode support
- 🔄 JWT Token Management - Automatic token refresh and secure storage
- 💾 Secure Storage - Cross-platform secure storage with AsyncStorage fallback
- 🚦 Rate Limiting - Built-in rate limiting with exponential backoff
- 📡 Context API - Global state management for authentication
- 🧭 React Navigation - Smooth navigation between auth and app flows
- ✨ TypeScript Ready - Fully typed for better development experience
- 🎨 Customizable - Easy to customize colors, fonts, and layouts
src/
├── api/
│ └── firebase.js # Firebase configuration and initialization
├── auth/
│ ├── AuthProvider.js # Context provider for authentication state
│ ├── authActions.js # Authentication actions (login, register, logout)
│ └── useAuth.js # Custom hook for auth operations
├── components/
│ ├── CustomButton.js # Reusable button component
│ └── CustomInput.js # Reusable input component with validation
├── navigation/
│ ├── AppStack.js # Navigation for authenticated users
│ ├── AuthStack.js # Navigation for unauthenticated users
│ └── RootNavigator.js # Main navigation controller
├── screens/
│ ├── HomeScreen.js # Main app screen
│ ├── LoginScreen.js # Login form
│ ├── ProfileScreen.js # User profile and settings
│ └── RegisterScreen.js # Registration form
├── utils/
│ ├── delay.js # Rate limiting utilities
│ └── storage.js # Secure storage utilities
└── App.js # Main app component
npm install
# or
yarn install- Create a new project at Firebase Console
- Enable Authentication with Email/Password
- Get your configuration from Project Settings
- Copy
env.exampleto.env - Fill in your Firebase configuration:
EXPO_PUBLIC_FIREBASE_API_KEY=your_api_key
EXPO_PUBLIC_FIREBASE_AUTH_DOMAIN=your_project.firebaseapp.com
EXPO_PUBLIC_FIREBASE_PROJECT_ID=your_project_id
EXPO_PUBLIC_FIREBASE_STORAGE_BUCKET=your_project.firebasestorage.app
EXPO_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=your_sender_id
EXPO_PUBLIC_FIREBASE_APP_ID=your_app_idnpm start
# or
yarn startConfigure rate limiting in src/utils/delay.js:
const RATE_LIMIT_CONFIG = {
MAX_LOGIN_ATTEMPTS: 5,
MAX_REGISTER_ATTEMPTS: 3,
LOGIN_COOLDOWN_MINUTES: 15,
REGISTER_COOLDOWN_MINUTES: 5,
BASE_DELAY_MS: 1000,
MAX_DELAY_MS: 10000,
};Colors and styling can be customized in each component's StyleSheet. Common colors used:
- Primary:
#007AFF - Secondary:
#F2F2F7 - Success:
#34C759 - Warning:
#FF9500 - Error:
#FF3B30 - Text:
#1D1D1F - Secondary Text:
#8E8E93
import { useAuth } from './src/auth/useAuth';
const MyComponent = () => {
const {
// State
isAuthenticated,
user,
isLoading,
error,
// Actions
login,
register,
logout,
resetPassword,
clearError,
// Computed values
userEmail,
userId,
userDisplayName,
isEmailVerified,
} = useAuth();
return (
// Your component JSX
);
};import CustomButton from './src/components/CustomButton';
<CustomButton
title="Sign In"
onPress={handleLogin}
loading={isLoading}
variant="primary" // primary, secondary, outline, text
size="medium" // small, medium, large
/>import CustomInput from './src/components/CustomInput';
<CustomInput
label="Email"
placeholder="Enter your email"
value={email}
onChangeText={setEmail}
keyboardType="email-address"
error={emailError}
required
/>- Secure Storage: Uses Expo SecureStore on mobile, AsyncStorage on web
- Token Management: Automatic JWT refresh and secure storage
- Rate Limiting: Prevents brute force attacks with exponential backoff
- Input Validation: Client-side validation for forms
- Error Handling: Comprehensive error handling with user-friendly messages
# Build for iOS
expo build:ios
# Build for Android
expo build:android
# Or use EAS Build (recommended)
eas build --platform allMake sure to set up environment variables in your deployment platform:
- Vercel: Add to project settings
- Netlify: Add to build environment
- EAS: Use
eas secret:create
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
If you have any questions or run into issues:
- Check the Issues page
- Create a new issue with detailed information
- Include device information, error messages, and steps to reproduce
- Expo for the amazing development platform
- Firebase for authentication services
- React Navigation for navigation
- The React Native community for inspiration and support
Built with ❤️ for the React Native community