Technologia

Firebase

Backend-as-a-Service od Google. Baza danych, auth, storage, hosting, functions — cały backend bez pisania serwera.

Czym jest Firebase?

Firebase to platforma Backend-as-a-Service (BaaS) od Google. Oferuje gotowe usługi backendowe: bazę danych NoSQL (Firestore), autentykację, storage, hosting, Cloud Functions, analytics, push notifications i wiele więcej.

Firebase pozwala zbudować pełny backend bez pisania serwera. Idealny do MVP, startupów i aplikacji real-time. Skaluje się automatycznie i oferuje model pay-as-you-go z hojnym darmowym tier.

Przykłady kodu

Firestore — CRUD

TypeScript + Firebase import { collection, doc, addDoc, getDocs, query, where, orderBy } from 'firebase/firestore'; // Dodaj użytkownika const createUser = async (data: CreateUserDTO) => { const ref = await addDoc(collection(db, 'users'), { ...data, createdAt: serverTimestamp(), }); return ref.id; }; // Pobierz aktywnych użytkowników const getActiveUsers = async () => { const q = query( collection(db, 'users'), where('isActive', '==', true), orderBy('createdAt', 'desc'), ); const snap = await getDocs(q); return snap.docs.map(d => ({ id: d.id, ...d.data() })); };

Firebase Auth

TypeScript import { signInWithPopup, GoogleAuthProvider, onAuthStateChanged } from 'firebase/auth'; // Google Sign-In const signInWithGoogle = async () => { const provider = new GoogleAuthProvider(); const result = await signInWithPopup(auth, provider); return result.user; }; // Obserwuj stan autentykacji onAuthStateChanged(auth, (user) => { if (user) { console.log('Zalogowany:', user.displayName); } else { console.log('Wylogowany'); } });

Cloud Functions

Cloud Functions (Node.js) import { onDocumentCreated } from 'firebase-functions/v2/firestore'; import { getMessaging } from 'firebase-admin/messaging'; // Trigger: nowy zamówienie → wyślij push export const onNewOrder = onDocumentCreated( 'orders/{orderId}', async (event) => { const order = event.data?.data(); if (!order) return; await getMessaging().send({ token: order.userFcmToken, notification: { title: 'Nowe zamówienie!', body: `Zamówienie #${event.params.orderId} zostało złożone.`, }, }); } );

Security Rules

Firestore Rules rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { // Użytkownik widzi tylko swoje dane match /users/{userId} { allow read: if request.auth.uid == userId; allow write: if request.auth.uid == userId && request.resource.data.keys() .hasOnly(['name', 'avatar', 'bio']); } // Admin widzi wszystko match /{document=**} { allow read, write: if request.auth.token.admin == true; } } }

Ocena kompetencji

Szybkość startu
99%
Real-time
98%
Auth
95%
Skalowalność
85%
Złożone query
55%
Vendor lock-in
35%

Co potrafi Firebase

Firestore (baza danych)

NoSQL, real-time sync, offline support, auto-scaling. Kolekcje, dokumenty, subkolekcje.

Authentication

Google, Apple, Facebook, email/password, phone, anonymous. MFA, custom claims, SSO.

Cloud Functions

Serverless backend. Triggers (Firestore, Auth, Storage), HTTP callable, scheduled.

Cloud Storage

Upload plików, obrazów, video. Resize, thumbnails. Security rules per-file.

Hosting

CDN, SSL, custom domains. Preview channels, rollbacks. Idealne do SPA i SSR.

Analytics & Crashlytics

Event tracking, user properties, funnels. Crash reporting, ANR detection.

Kiedy wybrać Firebase?

Idealny gdy: budujesz MVP, potrzebujesz real-time sync, chcesz szybki start bez pisania backendu, budujesz chat, social app, marketplace z auth i storage.

Nie najlepszy gdy: potrzebujesz złożonych relacji SQL (lepiej PostgreSQL), chcesz uniknąć vendor lock-in (lepiej Supabase), budujesz heavy-compute backend (lepiej Go/Python).