A comprehensive React Native (Expo) application with subscription-based authentication using Firebase Auth and in-app purchases.
[Expo App] -> [Express API] -> [Apple/Google APIs]
-> [Firebase Admin SDK]
- Frontend: Expo (React Native)
- Authentication: Firebase Authentication
- Backend: Express.js (Node.js)
- Database: Firestore
- Payments:
- iOS: Apple In-App Purchases (StoreKit)
- Android: Google Play Billing
- Unified handling: expo-in-app-purchases
LearnAi/
βββ Front-end/
β βββ services/
β β βββ firebaseConfig.ts # Firebase configuration
β β βββ authService.ts # Authentication service
β β βββ subscriptionService.ts # In-app purchase service
β βββ contexts/
β β βββ AuthContext.tsx # Authentication context
β βββ app/components/
β β βββ login.tsx # Login/Signup component
β β βββ subscriptionScreen.tsx # Subscription screen
β β βββ authGuard.tsx # Route protection
β βββ .env # Environment variables
βββ Back-end/
β βββ config/
β β βββ firebase.js # Firebase Admin SDK config
β βββ routes/
β β βββ auth.js # Authentication routes
β β βββ subscriptions.js # Subscription routes
β βββ services/
β β βββ receiptVerification.js # Receipt verification
β βββ server.js # Main server file
β βββ .env # Environment variables
- Create a Firebase project at https://firebase.google.com/
- Enable Authentication with Email/Password
- Enable Firestore Database
- Generate a Firebase Admin SDK private key
- Get your Firebase web app configuration
- Enroll in Apple Developer Program
- Create your app in App Store Connect
- Set up in-app purchase products:
- Monthly subscription:
learn_ai_monthly
- Yearly subscription:
learn_ai_yearly
- Monthly subscription:
- Generate App Store Connect API key
- Get your bundle ID and other credentials
- Create Google Play Developer account
- Create your app in Google Play Console
- Set up subscription products:
- Monthly subscription:
learn_ai_monthly_android
- Yearly subscription:
learn_ai_yearly_android
- Monthly subscription:
- Create service account for Google Play API
- Enable Google Play Developer API
LOCAL_HTTP_SERVER=http://localhost:3000
EXPO_PUBLIC_FIREBASE_API_KEY=your-firebase-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.appspot.com
EXPO_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=123456789
EXPO_PUBLIC_FIREBASE_APP_ID=1:123456789:web:abcdef
# Server
PORT=3000
NODE_ENV=development
# Firebase Admin
FIREBASE_PROJECT_ID=your-project-id
FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"
FIREBASE_CLIENT_EMAIL=firebase-adminsdk-xxxxx@your-project.iam.gserviceaccount.com
# Apple App Store
APPLE_ISSUER_ID=your-issuer-id
APPLE_KEY_ID=your-key-id
APPLE_BUNDLE_ID=com.yourcompany.learnai
APPLE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"
APPLE_SHARED_SECRET=your-shared-secret
# Google Play
GOOGLE_PLAY_PACKAGE_NAME=com.yourcompany.learnai
GOOGLE_SERVICE_ACCOUNT_KEY={"type":"service_account",...}
# Gemini AI (existing)
GEMINI_API_KEY=your-gemini-api-key
cd Back-end
npm install
npm start
cd Front-end
npm install
npx expo start
- User opens app β sees subscription screen
- User chooses monthly/yearly plan
expo-in-app-purchases
handles purchase- App sends receipt to backend for verification
- Backend verifies with Apple/Google APIs
- If valid, user can create account
- Firebase Auth creates user account
- User is signed in and can access app
- User enters email/password
- Firebase Auth validates credentials
- App checks subscription status with backend
- If subscription valid β user accesses app
- If subscription expired β redirect to subscription screen
- Displays available subscription plans
- Handles in-app purchases
- Communicates with backend for verification
- Manages purchase restoration
- Multi-mode component (login/signup/forgot password)
- Integrated with subscription flow
- Form validation and error handling
- Responsive design
- Protects routes requiring authentication
- Shows loading states
- Redirects to login when needed
- Manages global authentication state
- Provides auth methods to components
- Handles automatic subscription validation
- Firebase Admin SDK for server-side user management
- Receipt verification with Apple/Google APIs
- JWT token validation for API requests
- Subscription status validation on each app launch
- Automatic logout on subscription expiry
POST /check-subscription
- Check user subscription statusPOST /create-profile
- Create user profileGET /profile
- Get user profilePUT /profile
- Update user profileDELETE /account
- Delete user account
POST /verify
- Verify purchase receiptPOST /link-to-user
- Link subscription to userPOST /status
- Check subscription statusGET /history/:uid
- Get subscription historyPUT /update-status
- Update subscription status
- Use sandbox environments for testing:
- Apple: TestFlight or Simulator
- Google: Internal testing track
- Test subscription flows thoroughly
- Verify receipt validation works correctly
- Test edge cases (network failures, invalid receipts)
- Expo In-App Purchases Documentation
- Firebase Authentication
- Apple App Store Server API
- Google Play Billing
For issues and questions:
- Check the documentation
- Review error logs
- Test in sandbox environments first
- Verify all credentials are correctly configured
This project is licensed under the MIT License.