firebase-auth-basics

bởi firebase

Thiết lập Firebase Authentication với nhiều nhà cung cấp danh tính và bảo vệ quyền truy cập dữ liệu. Hỗ trợ email/mật khẩu, số điện thoại, ẩn danh, các nhà cung cấp liên kết (Google, Facebook, Twitter, GitHub, Microsoft, Apple) và tích hợp xác thực tùy chỉnh. Người dùng được xác định bằng UID duy nhất với các thuộc tính tùy chọn bao gồm email, tên hiển thị, URL ảnh và trạng thái xác minh email. Xác thực qua CLI cho phép Đăng nhập Google, xác thực ẩn danh và email/mật khẩu; các nhà cung cấp khác yêu cầu Firebase...

npx skills add https://github.com/firebase/skills --skill firebase-auth-basics

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://example.com", "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, ensure localhost is included in the Authorized Domains list in the Firebase Console or via the authorizedDomains field in firebase.json. CRITICAL: Do NOT include the protocol or port number in the Authorized Domains list (e.g., use localhost, NOT http://localhost:9090).

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.

3. Security Rules

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

See references/security_rules.md.

Thêm skills từ firebase

firebase-remote-config-basics
firebase
Hướng dẫn toàn diện về Firebase Remote Config, bao gồm quản lý template và cách sử dụng SDK. Sử dụng kỹ năng này khi người dùng cần trợ giúp thiết lập Remote Config, quản lý feature flag, hoặc cập nhật hành vi ứng dụng một cách linh hoạt.
officialdevelopmentapi
developing-genkit-dart
firebase
SDK AI hợp nhất cho Dart hỗ trợ tạo mã, đầu ra có cấu trúc, công cụ, luồng và tác nhân. Cung cấp API cốt lõi cho việc tạo sinh, định nghĩa công cụ, điều phối luồng, nhúng và phát trực tuyến với một giao diện duy nhất. Bao gồm 8+ plugin cho các nhà cung cấp LLM (Google Gemini, Anthropic Claude, OpenAI GPT), Firebase AI, Giao thức Ngữ cảnh Mô hình, tích hợp trình duyệt Chrome và lưu trữ máy chủ HTTP qua Shelf. CLI tích hợp sẵn với giao diện phát triển cục bộ để thực thi luồng, theo dõi, thử nghiệm mô hình và...
official
developing-genkit-go
firebase
Phát triển ứng dụng AI sử dụng Genkit trong Go. Sử dụng khi người dùng yêu cầu xây dựng tính năng AI, tác nhân, luồng hoặc công cụ trong Go bằng Genkit, hoặc khi làm việc…
official
developing-genkit-js
firebase
Xây dựng ứng dụng Node.js/TypeScript hỗ trợ AI với các luồng, công cụ và hỗ trợ đa mô hình của Genkit. Genkit không phụ thuộc vào nhà cung cấp; hỗ trợ Google AI, OpenAI, Anthropic, Ollama và các nhà cung cấp LLM khác thông qua plugin. Xác định luồng với lược đồ an toàn kiểu dữ liệu sử dụng Zod, thực thi các yêu cầu sinh và soạn thảo quy trình AI đa bước trong TypeScript. Yêu cầu Genkit CLI v1.29.0+; các thay đổi API lớn gần đây có nghĩa là bạn phải tham khảo tài liệu genkit:read và common-errors.md để biết các mẫu hiện tại, không dựa vào kiến thức trước đó...
official
developing-genkit-python
firebase
Phát triển ứng dụng hỗ trợ AI bằng Genkit trong Python. Sử dụng khi người dùng hỏi về Genkit, tác nhân AI, luồng hoặc công cụ trong Python, hoặc khi gặp Genkit…
official
firebase-ai-logic
firebase
Tích hợp Gemini phía máy khách cho ứng dụng web với suy luận đa phương thức, phát trực tuyến và thực thi kết hợp trên thiết bị. Hỗ trợ đầu vào chỉ văn bản và đa phương thức (hình ảnh, âm thanh, video, PDF); các tệp trên 20 MB được định tuyến qua Cloud Storage. Bao gồm các phiên trò chuyện với lịch sử tự động, phản hồi phát trực tuyến để hiển thị thời gian thực và thực thi đầu ra JSON có cấu trúc. Cung cấp suy luận kết hợp trên thiết bị qua Gemini Nano trong Chrome, với khả năng dự phòng tự động lên đám mây. Yêu cầu App Check cho môi trường sản xuất...
official
firebase-ai-logic-basics
firebase
Kỹ năng chính thức để tích hợp Firebase AI Logic (Gemini API) vào ứng dụng web. Bao gồm thiết lập, suy luận đa phương thức, đầu ra có cấu trúc và bảo mật.
official
firebase-app-hosting-basics
firebase
Triển khai và quản lý ứng dụng web full-stack với Firebase App Hosting sử dụng Next.js, Angular và các framework được hỗ trợ khác. Yêu cầu dự án Firebase ở gói giá Blaze; hỗ trợ quy trình Server-Side Rendering (SSR) và Incremental Static Regeneration (ISR). Triển khai qua cấu hình firebase.json với tệp apphosting.yaml tùy chọn cho thiết lập backend, hoặc kích hoạt triển khai tự động "git push to deploy" thông qua tích hợp GitHub. Bao gồm quản lý bí mật qua lệnh CLI để truy cập an toàn vào các khóa nhạy cảm...
official