Generated banner for Firebase Auth Basics
Generated logo for Firebase Auth Basics

Firebase Auth Basics

Firebase (Google)OfficialCreated by Google LLCDistributed by Firebase (Google)

  • Skill
  • Tool integration
  • Cloud and DevOps
  • Apache-2.0
  • Low risk

From the author

Guide for setting up and using Firebase Authentication. Use this skill when the user's app requires user sign-in, user management, or secure data access using auth rules.
— the description by Google LLC

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

This skill provides a foundational guide for implementing Firebase Authentication, covering core concepts like user identification, identity providers, and token management. It outlines the necessary steps for provisioning authentication services via the Firebase CLI or Console and provides integration patterns for various client platforms including Web, Android, iOS, and Flutter. It also addresses critical configuration requirements such as authorized domains and security rule integration.

What it does

  • Explains core Firebase Auth concepts including UIDs, identity providers, and JWT tokens.
  • Provides procedures for enabling authentication providers via the Firebase CLI and Console.
  • Offers guidance on configuring authorized domains to prevent common OAuth errors.
  • Details client-side initialization patterns for Web and Android platforms.
  • Outlines the use of security rules to protect data access based on user authentication state.

When to use it

  • When you need to implement user sign-in and management in a new or existing application.
  • When you need to secure your Firestore or Cloud Storage data using authentication rules.
  • When you are setting up federated identity providers like Google, Facebook, or Apple.
  • When you need to troubleshoot authentication domain authorization issues.

Advantages

  • Supports multiple authentication methods including email, social providers, and anonymous access.
  • Provides a unified identity model across different client platforms.
  • Includes clear instructions for avoiding common configuration pitfalls like port-related domain errors.
  • Integrates directly with other Firebase services for secure data access.

Usage examples

“How do I enable Google Sign-In for my Firebase project using the CLI?”
The agent will provide the structure for the auth block in firebase.json and the command to deploy the configuration.
“How do I initialize Firebase Auth in an Android Kotlin app?”
The agent will provide the Gradle dependency setup and the code snippet for initializing the FirebaseAuth instance in an Activity.
“I am getting an auth/unauthorized-domain error, how do I fix it?”
The agent will explain how to add your domain to the Authorized Domains list in the Firebase Console without including protocol or port numbers.

Install

  1. Download the skill as a ZIP:

    https://autogineer.com/agent-skills/firebase/firebase-auth-basics/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip firebase-auth-basics.zip -d .agents/skills

Documentation by Google LLC

Prerequisites

  • Firebase Project: Created via npx -y firebase-tools@latest projects:create (see firebase-basics).

  • Firebase CLI: Installed and logged in (see firebase-basics).

Core Concepts

Firebase Authentication provides backend services, easy-to-use SDKs, and ready-made UI libraries to authenticate users to your app.

Users

A user is an entity that can sign in to your app. Each user is identified by a unique ID (uid) which is guaranteed to be unique across all providers. User properties include:

  • uid: Unique identifier.

  • email: User's email address (if available).

  • displayName: User's display name (if available).

  • photoURL: URL to user's photo (if available).

  • emailVerified: Boolean indicating if the email is verified.

Identity Providers

Firebase Auth supports multiple ways to sign in:

  • Email/Password: Basic email and password authentication.

  • Federated Identity Providers: Google, Facebook, Twitter, GitHub, Microsoft, Apple, etc.

  • Phone Number: SMS-based authentication.

  • Anonymous: Temporary guest accounts that can be linked to permanent accounts later.

  • Custom Auth: Integrate with your existing auth system.

Google Sign In is recommended as a good and secure default provider.

Tokens

When a user signs in, they receive an ID Token (JWT). This token is used to identify the user when making requests to Firebase services (Realtime Database, Cloud Storage, Firestore) or your own backend.

  • ID Token: Short-lived (1 hour), verifies identity.

  • Refresh Token: Long-lived, used to get new ID tokens.

Workflow

1. Provisioning
Option 1. Enabling Authentication via CLI

Only Google Sign In, anonymous auth, and email/password auth can be enabled via CLI. For other providers, use the Firebase Console.

Configure Firebase Authentication in firebase.json by adding an 'auth' block:

{
  "auth": {
    "providers": {
      "anonymous": true,
      "emailPassword": true,
      "googleSignIn": {
        "oAuthBrandDisplayName": "Your Brand Name",
        "supportEmail": "[email protected]",
        "authorizedRedirectUris": [
          "https://my-project-id.firebaseapp.com/__/auth/handler",
          "http://localhost"
        ]
      }
    }
  }
}

[!NOTE] If the Google Sign-In popup opens and immediately closes with the error [firebase_auth/unauthorized-domain], it means the domain is not authorized. For local development, add http://localhost to authorizedRedirectUris in firebase.json (or ensure localhost is included in the Authorized Domains list in the Firebase Console under Authentication > Settings > Authorized domains). CRITICAL: Do NOT include the port number in authorizedRedirectUris (e.g., use http://localhost, NOT http://localhost:9090 or http://localhost:4000), and do NOT include the protocol or port number in the Console Authorized Domains list (use localhost). Including a port number in authorizedRedirectUris causes firebase deploy --only auth to fail with INVALID_AUTHORIZED_DOMAIN.

CRITICAL: After configuring firebase.json, you MUST deploy the auth configuration to the Firebase backend for the changes to take effect. This is essential for auth providers like Google Sign-In, email/password, etc. to auto-generate the necessary OAuth clients for your app platforms. Run:

npx -y firebase-tools@latest deploy --only auth
Option 2. Enabling Authentication in Console

Enable other providers in the Firebase Console.

  1. Go to the https://console.firebase.google.com/project/_/authentication/providers

  2. Select your project.

  3. Enable the desired Sign-in providers (e.g., Email/Password, Google).

2. Client Setup & Usage

Web See references/client_sdk_web.md.

Flutter See references/flutter_setup.md. Android (Kotlin) See references/client_sdk_android.md.

iOS (Swift) See references/ios_setup.md.

3. Security Rules

Secure your data using request.auth in Firestore/Storage rules.

See references/security_rules.md.

Files

references/flutter_setup.md

Firebase Auth & Google Sign-In for Flutter

When integrating Firebase Authentication and Google Sign-In into Flutter apps targeting cross-platform environments (like Mobile + Web), you must navigate several breaking changes introduced in google_sign_in 7.x+ and some platform-specific quirks.

1. google_sign_in 7.2.0 API Changes

  • Method Renamed: The signIn() method is deprecated/removed and has been replaced with authenticate().

  • Token Separation: The GoogleSignInAuthentication object no longer packages both identity and authorization tokens together. Initial authentication now only provides the idToken. If an accessToken is required for Google APIs, you must explicitly request server authorization separately.

2. Initialization & Web Hang/Crash Pitfalls

  • Initialization Requirement: In 7.x, you must call await GoogleSignIn.instance.initialize(); globally before using the plugin.

  • Web Client ID Constraint: On Flutter Web, if you call initialize() without passing a clientId argument OR specifying the <meta name="google-signin-client_id" ... /> tag in web/index.html, the Dart Web Debug Service (DWDS) and the app will throw an assertion error and hang infinitely, resulting in a blank screen.

  • Common Workaround: If you intend to use Firebase Auth's signInWithPopup(GoogleAuthProvider()) for the web, you can conditionally skip the local GoogleSignIn package initialization entirely:

    import 'package:flutter/foundation.dart' show kIsWeb;
    
    if (!kIsWeb) {
    await GoogleSignIn.instance.initialize();
    }

3. Web Logout Crashes

  • If you bypassed GoogleSignIn initialization on the web (as demonstrated above), you cannot call its signOut() method later. Attempting to execute await GoogleSignIn.instance.signOut(); during the user's logout flow on the Web platform evaluates against an uninitialized context or unsupported environment, crashing the app.

  • Solution: Conditionally separate the logout logic for Web to rely entirely on FirebaseAuth:

    if (!kIsWeb) {
      await GoogleSignIn.instance.signOut();
    }
    await FirebaseAuth.instance.signOut();

4. Prototyping Workaround: Bypassing Firestore Composite Indices

Note: This is a Firestore consideration frequently encountered while fetching user-specific auth data.

When querying data via FirebaseFirestore.instance, using .where('userId', isEqualTo: uid) combined with a sort on a different field like .orderBy('createdAt', descending: true) mandates a custom composite index.

  • Quick Alternative: During local development, you can avoid defining indexes by pulling the data using only .where() and applying the .sort() operation client-side on the resulting List in Dart.

5. Robust AuthService Boilerplate

Here is a comprehensive AuthService implementation that properly handles the initialization and platform differences between Flutter Web and Mobile:

import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/foundation.dart';
import 'package:google_sign_in/google_sign_in.dart';

class AuthService {
  final FirebaseAuth _auth = FirebaseAuth.instance;

  AuthService() {
    if (!kIsWeb) {
      GoogleSignIn.instance.initialize();
    }
  }

  // Stream to listen to auth state changes
  Stream<User?> get authStateChanges => _auth.authStateChanges();

  // Get current user
  User? get currentUser => _auth.currentUser;

  // Google Sign-In
  Future<UserCredential?> signInWithGoogle() async {
    try {
      if (kIsWeb) {
        // Web uses popup to avoid DWDS hangs and manual client ID config
        GoogleAuthProvider authProvider = GoogleAuthProvider();
        return await _auth.signInWithPopup(authProvider);
      } else {
        // Mobile uses standard flow
        final GoogleSignInAccount googleUser = await GoogleSignIn.instance.authenticate();
        final GoogleSignInAuthentication googleAuth = googleUser.authentication;

        final AuthCredential credential = GoogleAuthProvider.credential(
          idToken: googleAuth.idToken,
        );

        return await _auth.signInWithCredential(credential);
      }
    } catch (e) {
      print("Error during Google Sign-In: $e");
      return null;
    }
  }

  // Sign out
  Future<void> signOut() async {
    try {
      if (!kIsWeb) {
        await GoogleSignIn.instance.signOut();
      }
      await _auth.signOut();
    } catch (e) {
      print("Error signing out: $e");
    }
  }
}

6. Troubleshooting auth/unauthorized-domain on Flutter Web

When running Flutter Web locally and using signInWithPopup, you might encounter a situation where the Google Sign-In popup opens and immediately closes.

  • Symptom: The console shows Sign-in failed: [firebase_auth/unauthorized-domain] This domain is not authorized for OAuth operation for your Firebase project.

  • Cause: The domain (usually localhost during local testing) is not listed in the Authorized Domains in the Firebase Console.

  • Solution: Add localhost to the Authorized Domains list in the Firebase Console (Authentication > Settings > Authorized domains).

  • CRITICAL: Do NOT include the protocol or port number when adding the domain (e.g., use localhost, NOT http://localhost:9090). Flutter Web often runs on random ports or specific ports, but Firebase Auth only cares about the domain.

Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Needs: Needs Node.js

The author says: This skill is best used with the Firebase CLI, but does not require it. Firebase CLI can be accessed through `npx -y firebase-tools@latest`.

Security

What our scanner noticed· Low risk

  • Instructions that use the network

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Created by
Google LLC
Publisher
Firebase (Google) (Official)
Distributed by
Firebase (Google)
Source
firebase/agent-skills · skills/firebase-auth-basics · commit b76be96
Licence
Apache License 2.0 (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced

AutoGineer is not affiliated with or endorsed by Google LLC or Firebase (Google).

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download firebase-auth-basics.zip