RentSmart backend is built on Firebase, providing authentication and database services for property rental calculations and favorites management.
- Platform: Firebase (Google)
- Authentication: Firebase Auth (Email/Password + Google Sign-in)
- Database: Cloud Firestore (NoSQL)
- Hosting: Firebase Hosting (optional)
rentSmart/
βββ src/
β βββ config/
β β βββ firebase.js # Firebase initialization
β βββ services/
β βββ authService.js # Authentication operations
β βββ firestoreService.js # Database operations
βββ firestore.rules # Security rules
βββ firestore.indexes.json # Database indexes
βββ firebase.json # Firebase configuration
βββ .env.example # Environment variables template
βββ package.json # Dependencies
- Node.js (v16 or higher)
- npm or yarn
- Firebase account
npm install- Go to Firebase Console
- Click "Add project"
- Enter project name (e.g., "rentsmart")
- Follow the setup wizard
- In Firebase Console, go to Authentication
- Click "Get started"
- Enable Email/Password sign-in method
- Enable Google sign-in method (optional but recommended)
- In Firebase Console, go to Firestore Database
- Click "Create database"
- Choose Start in production mode (we have security rules)
- Select your preferred location
- Go to Project Settings (gear icon)
- Scroll to "Your apps" section
- Click the web icon (
</>) to add a web app - Register your app with a nickname
- Copy the Firebase configuration object
-
Copy
.env.exampleto.env:cp .env.example .env
-
Fill in your Firebase credentials in
.env:VITE_FIREBASE_API_KEY=your_api_key_here VITE_FIREBASE_AUTH_DOMAIN=your_project_id.firebaseapp.com VITE_FIREBASE_PROJECT_ID=your_project_id VITE_FIREBASE_STORAGE_BUCKET=your_project_id.appspot.com VITE_FIREBASE_MESSAGING_SENDER_ID=your_sender_id VITE_FIREBASE_APP_ID=your_app_id VITE_FIREBASE_MEASUREMENT_ID=your_measurement_id
# Login to Firebase
npx firebase login
# Initialize Firebase (if not already done)
npx firebase init
# Deploy Firestore rules and indexes
npx firebase deploy --only firestore:rules,firestore:indexes# Start Firebase emulators
npm run firebase:emulatorsThis will start:
- Auth Emulator: http://localhost:9099
- Firestore Emulator: http://localhost:8080
- Emulator UI: http://localhost:4000
import { signUp } from './services/authService';
const result = await signUp('user@example.com', 'password123', 'John Doe');
if (result.success) {
console.log('User created:', result.user);
}import { signIn } from './services/authService';
const result = await signIn('user@example.com', 'password123');
if (result.success) {
console.log('Signed in:', result.user);
}import { signInWithGoogle } from './services/authService';
const result = await signInWithGoogle();
if (result.success) {
console.log('Signed in with Google:', result.user);
}import { logOut } from './services/authService';
await logOut();import { onAuthChange } from './services/authService';
const unsubscribe = onAuthChange((user) => {
if (user) {
console.log('User is signed in:', user);
} else {
console.log('User is signed out');
}
});
// Cleanup
unsubscribe();import { saveCalculation } from './services/firestoreService';
const calculationData = {
propertyAddress: '123 Main St',
monthlyRent: 2000,
expenses: 500,
netIncome: 1500
};
const result = await saveCalculation(userId, calculationData);
if (result.success) {
console.log('Calculation saved with ID:', result.id);
}import { getUserCalculations } from './services/firestoreService';
const result = await getUserCalculations(userId);
if (result.success) {
console.log('Calculations:', result.calculations);
}import { saveToFavorites } from './services/firestoreService';
const propertyData = {
address: '456 Oak Ave',
price: 350000,
bedrooms: 3,
bathrooms: 2
};
const result = await saveToFavorites(userId, propertyData);import { getUserFavorites } from './services/firestoreService';
const result = await getUserFavorites(userId);
if (result.success) {
console.log('Favorites:', result.favorites);
}Stores property rental calculations
userId(string): User ID who created the calculationcreatedAt(timestamp): Creation timestampupdatedAt(timestamp): Last update timestamp- Custom fields for calculation data
Stores user's favorite properties
userId(string): User IDcreatedAt(timestamp): When favorited- Custom fields for property data
Stores complete property information with calculations
userId(string): User IDcreatedAt(timestamp): Creation timestampupdatedAt(timestamp): Last update timestamp- Custom fields for property and calculation data
- Users can only read/write their own data
- All operations require authentication
- Data is scoped by
userIdfield
- Never commit
.envfile - Keep Firebase API keys in environment variables
- Use Firestore security rules to protect data
- Validate data on the client before saving
# Build your app
npm run build
# Deploy to Firebase
npm run firebase:deploy-
"Permission denied" errors
- Ensure user is authenticated
- Check Firestore security rules
- Verify
userIdmatches authenticated user
-
Environment variables not loading
- Ensure
.envfile exists - Restart development server
- Check variable names start with
VITE_
- Ensure
-
Firebase initialization errors
- Verify all config values in
.env - Check Firebase project is active
- Ensure billing is enabled (for production)
- Verify all config values in
- β Backend setup complete
- π Create frontend UI components
- π Integrate auth with UI
- π Build property calculation forms
- π Implement favorites management
- π Add data visualization
For Firebase documentation, visit: https://firebase.google.com/docs