Firebase Auth Integration for Website

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1212
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    852
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    815

Firebase Auth Integration for Website

Firebase Authentication is Google's service for authentication management. Out-of-the-box supports email/password, Google, Facebook, Apple, Twitter, GitHub, phone, and anonymous login. SDK available for JS, iOS, Android, Web.

Main use case: SPA or mobile app on Firebase, backend is Laravel API. Firebase issues JWT (ID Token), Laravel verifies signature via Google public keys.

Firebase Frontend Initialization

Install Firebase SDK and initialize with config from Firebase Console:

import { initializeApp } from 'firebase/app';
import { getAuth } from 'firebase/auth';

const firebaseConfig = {
  apiKey: "YOUR_API_KEY",
  authDomain: "YOUR_AUTH_DOMAIN",
  projectId: "YOUR_PROJECT_ID",
  // ... other config
};

const app = initializeApp(firebaseConfig);
export const auth = getAuth(app);

Email/Password Login

import { signInWithEmailAndPassword } from 'firebase/auth';

async function login(email: string, password: string) {
  try {
    const result = await signInWithEmailAndPassword(auth, email, password);
    const user = result.user;
    const idToken = await user.getIdToken();

    // Send idToken to backend
    await fetch('/api/auth/firebase-login', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ idToken })
    });
  } catch (error) {
    console.error('Login failed:', error);
  }
}

Google OAuth via Firebase

import { signInWithPopup, GoogleAuthProvider } from 'firebase/auth';

const provider = new GoogleAuthProvider();

async function loginWithGoogle() {
  const result = await signInWithPopup(auth, provider);
  const idToken = await result.user.getIdToken();

  // Send to backend
  await fetch('/api/auth/firebase-login', {
    method: 'POST',
    body: JSON.stringify({ idToken })
  });
}

Laravel: Verify Firebase ID Token

Firebase publishes public keys for JWT verification:

// Verify using Firebase Admin SDK
use Kreait\Firebase\Factory;

$firebase = (new Factory)
    ->withServiceAccount('/path/to/serviceAccountKey.json');

$auth = $firebase->createAuth();
$verifiedIdToken = $auth->verifyIdToken($idToken);

$uid = $verifiedIdToken->claims()->get('sub');

Verify Without Firebase Admin SDK

If full Firebase Admin SDK not needed — verify JWT via JWKS directly:

use Firebase\JWT\JWT;
use Firebase\JWT\Key;

$jwksUri = 'https://www.googleapis.com/robot/v1/metadata/x509/[email protected]';
$jwks = json_decode(file_get_contents($jwksUri), true);

$key = $jwks['keys'][0]; // Simplified, actually need to find by kid
$publicKey = "-----BEGIN CERTIFICATE-----\n" . wordwrap($key['x5c'][0], 64, "\n", true) . "\n-----END CERTIFICATE-----";

$decoded = JWT::decode($idToken, new Key($publicKey, 'RS256'));
$uid = $decoded->sub;

Working with Token on Client

Firebase ID Token expires in 1 hour. Client must refresh it:

auth.onAuthStateChanged(async (user) => {
  if (user) {
    const idToken = await user.getIdToken();
    // Use token in API requests
    // Token automatically refreshes when expired
  }
});

Phone Authentication

Firebase supports SMS verification for phone-based login.

Limitations

  • Firebase Authentication free up to 10,000 active users per month (Spark plan)
  • Phone Auth: 10 SMS/day on Spark, then paid
  • Data stored on Google servers — not suitable for projects requiring data localization

Implementation Timeline

Stage Time
Firebase project setup 0.5 day
Frontend SDK + providers 1 day
Laravel token verification 1 day
Token refresh + middleware 0.5 day
Tests 1 day

Total: 4–5 working days.