跳到主要内容
知仓学习社ZHICANG

Firebase Mobile

Firebase backend services integration for mobile apps

不碰外部(只输出文字)无严重或高危命中a5c-ai/babysitter

它会碰到什么

扫了多少2 个文本文件,7 KB
它会碰到什么不碰外部(只输出文字)
命中总数0 处
命中统计严重 0 · 高 0 · 中 0 · 低 0

这一栏是扫描器报的事实,不是结论。命中多不等于有毒(安全工具、规则库、示例脚本本来就会包含危险写法),命中少也不等于干净。它和你手上的凭据、文件、网络有什么关系,需要你自己看。

技能内容

Firebase Mobile Skill

Overview

This skill provides Firebase backend services integration for mobile applications. It enables configuration of Authentication, Firestore, Storage, Cloud Functions, and other Firebase services.

Allowed Tools

  • bash - Execute Firebase CLI commands
  • read - Analyze Firebase configurations
  • write - Generate security rules and configurations
  • edit - Update Firebase implementations
  • glob - Search for Firebase files
  • grep - Search for patterns

Capabilities

Firebase Authentication

  1. Auth Methods
  • Email/password authentication
  • OAuth providers (Google, Apple, Facebook)
  • Phone authentication
  • Anonymous authentication
  • Custom token authentication
  1. Auth State
  • Handle auth state changes
  • Token refresh
  • Session persistence
  • Multi-factor authentication

Cloud Firestore

  1. Database Operations
  • Document CRUD operations
  • Collection queries
  • Real-time listeners
  • Batch operations
  • Transactions
  1. Security Rules
  • Write Firestore rules
  • Test rules with emulator
  • Handle role-based access
  • Validate data structure

Firebase Storage

  1. File Operations
  • Upload files with progress
  • Download files
  • Generate download URLs
  • Handle metadata
  • Configure security rules

Cloud Functions

  1. Function Integration
  • Call HTTPS functions
  • Call callable functions
  • Handle function responses
  • Configure timeouts

Remote Config

  1. Feature Flags
  • Fetch remote config
  • Configure defaults
  • Handle fetch intervals
  • A/B testing setup

Performance Monitoring

  1. Performance Tracking
  • Automatic traces
  • Custom traces
  • Network request monitoring
  • Screen rendering metrics

Target Processes

  • firebase-backend-integration.js - Firebase integration
  • firebase-cloud-messaging.js - Push notifications
  • mobile-analytics-setup.js - Analytics

Dependencies

  • Firebase SDK
  • Firebase CLI
  • Google Cloud account

Usage Examples

Firebase Setup (iOS)

// AppDelegate.swift
import FirebaseCore
import FirebaseAuth
import FirebaseFirestore

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication,
                     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        FirebaseApp.configure()
        return true
    }
}

// AuthService.swift
class AuthService: ObservableObject {
    @Published var user: User?
    private var handle: AuthStateDidChangeListenerHandle?

    init() {
        handle = Auth.auth().addStateDidChangeListener { [weak self] _, user in
            self?.user = user
        }
    }

    func signIn(email: String, password: String) async throws {
        try await Auth.auth().signIn(withEmail: email, password: password)
    }

    func signUp(email: String, password: String) async throws {
        try await Auth.auth().createUser(withEmail: email, password: password)
    }

    func signOut() throws {
        try Auth.auth().signOut()
    }
}

Firestore Repository (Android)

// data/repository/PostRepository.kt
class PostRepository @Inject constructor(
    private val firestore: FirebaseFirestore
) {
    private val postsCollection = firestore.collection("posts")

    fun observePosts(): Flow<List<Post>> = callbackFlow {
        val listener = postsCollection
            .orderBy("createdAt", Query.Direction.DESCENDING)
            .addSnapshotListener { snapshot, error ->
                if (error != null) {
                    close(error)
                    return@addSnapshotListener
                }
                val posts = snapshot?.documents?.mapNotNull { it.toObject<Post>() } ?: emptyList()
                trySend(posts)
            }
        awaitClose { listener.remove() }
    }

    suspend fun createPost(post: Post): String {
        val docRef = postsCollection.add(post).await()
        return docRef.id
    }

    suspend fun updatePost(postId: String, updates: Map<String, Any>) {
        postsCollection.document(postId).update(updates).await()
    }

    suspend fun deletePost(postId: String) {
        postsCollection.document(postId).delete().await()
    }
}

Security Rules

// firestore.rules
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    function isAuthenticated() {
      return request.auth != null;
    }

    function isOwner(userId) {
      return isAuthenticated() && request.auth.uid == userId;
    }

    match /users/{userId} {
      allow read: if isAuthenticated();
      allow write: if isOwner(userId);
    }

    match /posts/{postId} {
      allow read: if true;
      allow create: if isAuthenticated()
        && request.resource.data.authorId == request.auth.uid;
      allow update, delete: if isOwner(resource.data.authorId);
    }
  }
}

Firebase Emulator

# Start emulators
firebase emulators:start

# Run with emulator in code
if ProcessInfo.processInfo.environment["USE_FIREBASE_EMULATOR"] == "YES" {
    Auth.auth().useEmulator(withHost: "localhost", port: 9099)
    Firestore.firestore().useEmulator(withHost: "localhost", port: 8080)
    Storage.storage().useEmulator(withHost: "localhost", port: 9199)
}

Quality Gates

  • Security rules tested with emulator
  • Authentication flows verified
  • Offline persistence tested
  • Error handling comprehensive

Related Skills

  • push-notifications - FCM integration
  • mobile-analytics - Firebase Analytics
  • mobile-security - Security patterns

Version History

  • 1.0.0 - Initial release

想直接用这个技能?

本站把开放许可(MIT / Apache 等)的技能按仓库打包整理到网盘,点一下转存到你自己的网盘,不用一个个从 GitHub 拉。许可未声明的技能只给原始仓库链接,不打包。

它属于哪个仓库

星标★ 1,796
本站分层T1
该仓技能数2115
原文件路径library/specializations/mobile-development/skills/firebase-mobile/SKILL.md

同一个仓库里的其他技能

看这个仓库的全部 2115 个技能