Skip to main content

Overview

LarpLand uses Firebase as its backend, providing authentication, real-time database, and file storage capabilities. This guide will walk you through setting up Firebase for your LarpLand project.
The project is designed to work on the firebase branch. The master branch uses a Laravel REST API backend.

Create a Firebase Project

1

Go to Firebase Console

Navigate to console.firebase.google.com and sign in with your Google account.
2

Create New Project

Click “Add project” and follow the setup wizard:
  • Enter a project name (e.g., “larpland”)
  • Choose whether to enable Google Analytics (optional)
  • Accept the terms and create the project
3

Wait for Initialization

Firebase will take a moment to provision your project resources.

Enable Firebase Services

Firebase Authentication

1

Navigate to Authentication

In the Firebase Console, go to BuildAuthentication
2

Get Started

Click “Get started” if this is your first time setting up Authentication
3

Enable Email/Password Provider

  • Go to the Sign-in method tab
  • Click on Email/Password
  • Enable the provider
  • Click Save
LarpLand uses email/password authentication. The app handles user registration and login through Firebase Auth.

Cloud Firestore Database

1

Navigate to Firestore

In the Firebase Console, go to BuildFirestore Database
2

Create Database

Click “Create database”
3

Choose Starting Mode

Select Test mode for development (allows read/write access for 30 days)
For production, you’ll need to configure proper security rules (covered below).
4

Select Location

Choose a Firestore location close to your users for better performance

Firebase Storage

1

Navigate to Storage

In the Firebase Console, go to BuildStorage
2

Get Started

Click “Get started”
3

Choose Starting Mode

Select Test mode for development
For production, configure proper security rules to restrict access.
4

Select Location

Choose a storage location (should match your Firestore region)

Configure FlutterFire

Install FlutterFire CLI

The FlutterFire CLI simplifies Firebase configuration across platforms:
dart pub global activate flutterfire_cli
Verify installation:
flutterfire --version

Run FlutterFire Configure

From your project root, run:
flutterfire configure
This command will:
  1. Prompt you to select your Firebase project
  2. Ask which platforms you want to configure (Android, iOS, Web, etc.)
  3. Generate lib/firebase_options.dart with platform-specific configurations
  4. Create platform configuration files (google-services.json, GoogleService-Info.plist)
Make sure you’re logged in with firebase login before running this command.

Platform-Specific Configuration

Android Configuration

Add google-services.json

The flutterfire configure command should automatically place google-services.json in the correct location:
android/app/google-services.json

Verify build.gradle Configuration

Ensure your android/app/build.gradle includes the Google Services plugin:
android/app/build.gradle
plugins {
    id "com.android.application"
    id "kotlin-android"
    id "dev.flutter.flutter-gradle-plugin"
    id "com.google.gms.google-services"  // Must be last
}
The project already includes this configuration.

Example google-services.json Structure

Your file should look similar to this:
android/app/google-services.json
{
  "project_info": {
    "project_number": "551562159252",
    "project_id": "larpland-c6689",
    "storage_bucket": "larpland-c6689.firebasestorage.app"
  },
  "client": [
    {
      "client_info": {
        "mobilesdk_app_id": "1:551562159252:android:f882bc8173a889a3af4081",
        "android_client_info": {
          "package_name": "com.example.larpland"
        }
      },
      "api_key": [
        {
          "current_key": "YOUR_ANDROID_API_KEY"
        }
      ]
    }
  ]
}
Replace example values with your actual Firebase project credentials.

Firebase Options File

The generated lib/firebase_options.dart file contains all platform configurations:
import 'package:firebase_core/firebase_core.dart' show FirebaseOptions;
import 'package:flutter/foundation.dart'
    show TargetPlatform, defaultTargetPlatform, kIsWeb;

class DefaultFirebaseOptions {
  static FirebaseOptions get currentPlatform {
    if (kIsWeb) {
      return web;
    }
    switch (defaultTargetPlatform) {
      case TargetPlatform.android:
        return android;
      case TargetPlatform.iOS:
        return ios;
      case TargetPlatform.macOS:
        return macos;
      case TargetPlatform.windows:
        return windows;
      case TargetPlatform.linux:
        return linux;
      default:
        throw UnsupportedError(
          'DefaultFirebaseOptions no soporta esta plataforma.',
        );
    }
  }

  // Platform-specific configurations
  static const FirebaseOptions android = FirebaseOptions(
    apiKey: 'YOUR_ANDROID_API_KEY',
    appId: 'YOUR_ANDROID_APP_ID',
    messagingSenderId: 'YOUR_MESSAGING_SENDER_ID',
    projectId: 'your-project-id',
    storageBucket: 'your-project.firebasestorage.app',
  );

  static const FirebaseOptions ios = FirebaseOptions(
    apiKey: 'YOUR_IOS_API_KEY',
    appId: 'YOUR_IOS_APP_ID',
    messagingSenderId: 'YOUR_MESSAGING_SENDER_ID',
    projectId: 'your-project-id',
    storageBucket: 'your-project.firebasestorage.app',
    iosBundleId: 'com.example.larpland',
  );

  // ... other platforms
}
Replace placeholder values with your actual Firebase credentials from the Firebase Console.

Firestore Security Rules

For production deployments, configure proper Firestore security rules:
firestore.rules
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    
    // User profiles - users can read/write their own profile
    match /users/{userId} {
      allow read: if request.auth != null;
      allow write: if request.auth != null && request.auth.uid == userId;
    }
    
    // Products - public read, admin write
    match /products/{productId} {
      allow read: if true;
      allow write: if request.auth != null && 
                     get(/databases/$(database)/documents/users/$(request.auth.uid)).data.rol == 1;
    }
    
    // Events - public read, admin write
    match /events/{eventId} {
      allow read: if true;
      allow write: if request.auth != null && 
                     get(/databases/$(database)/documents/users/$(request.auth.uid)).data.rol == 1;
    }
    
    // Orders - users can read/write their own orders
    match /orders/{orderId} {
      allow read: if request.auth != null && 
                    (request.auth.uid == resource.data.userId || 
                     get(/databases/$(database)/documents/users/$(request.auth.uid)).data.rol == 1);
      allow create: if request.auth != null;
    }
    
    // Reviews - authenticated users can write, everyone can read
    match /reviews/{reviewId} {
      allow read: if true;
      allow create: if request.auth != null;
      allow update, delete: if request.auth != null && 
                              request.auth.uid == resource.data.userId;
    }
  }
}
Deploy rules using the Firebase CLI:
firebase deploy --only firestore:rules

Storage Security Rules

Configure Firebase Storage security rules:
storage.rules
rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    
    // Product images - public read, admin write
    match /products/{allPaths=**} {
      allow read: if true;
      allow write: if request.auth != null && 
                     firestore.get(/databases/(default)/documents/users/$(request.auth.uid)).data.rol == 1;
    }
    
    // User avatars - users can upload their own
    match /users/{userId}/{allPaths=**} {
      allow read: if true;
      allow write: if request.auth != null && request.auth.uid == userId;
    }
  }
}
Deploy storage rules:
firebase deploy --only storage

Initialize Firebase in the App

The app automatically initializes Firebase in lib/main.dart:
import 'package:firebase_core/firebase_core.dart';
import 'package:larpland/firebase_options.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  var firebaseReady = false;
  if (DefaultFirebaseOptions.isConfigured) {
    await Firebase.initializeApp(
      options: DefaultFirebaseOptions.currentPlatform,
    );
    await AuthSession.syncFromFirebase();
    firebaseReady = true;
  }

  runApp(MyApp(firebaseReady: firebaseReady));
}
If Firebase is not configured, the app will display a setup screen with instructions.

Verify Firebase Setup

1

Run the App

Start the app on your device or emulator:
flutter run
2

Check for Firebase Setup Screen

If Firebase is not configured, you’ll see a setup screen with configuration instructions.If properly configured, you’ll see the login screen.
3

Test Registration

Try creating a new account to verify Firebase Authentication is working.
4

Check Firebase Console

Verify that new users appear in AuthenticationUsers tab in the Firebase Console.

Troubleshooting

Ensure lib/firebase_options.dart exists and contains valid credentials. Run flutterfire configure again if needed.
Make sure google-services.json is in android/app/ directory and the file is not empty.
  • Run cd ios && pod install && cd ..
  • Clean build folder: flutter clean
  • Rebuild: flutter build ios
Check your Firestore and Storage security rules. For development, you can temporarily use test mode rules.
In Firebase Console, go to Project SettingsCloud Messaging and ensure API keys are properly configured for your platforms.

Next Steps

Quick Start

Follow the quick start guide to get your app running

Firebase Documentation

Learn more about Firebase features and best practices

Build docs developers (and LLMs) love