Firebase Authentication 是一个面向 Web 和移动应用的认证服务,提供多种登录方式,适合移动应用认证、社交登录(如 Google、Apple)、电话号码认证以及匿名用户场景。
主要能力:支持邮箱密码注册与登录、社交登录弹窗(如 GoogleAuthProvider 配合 signInWithPopup)、匿名用户、电话号码登录,并能通过 onAuthStateChanged 监听登录状态变化,使用 user.getIdToken() 获取 ID Token。服务端可用 firebase-admin/auth 的 getAuth().verifyIdToken(token) 校验令牌。
使用方式(示例): const auth = getAuth(); await createUserWithEmailAndPassword(auth, email, password); await signInWithEmailAndPassword(auth, email, password); const user = auth.currentUser; 社交登录: const provider = new GoogleAuthProvider(); const result = await signInWithPopup(auth, provider); 状态监听: onAuthStateChanged(auth, (user) => { ... });
最佳实践:使用 onAuthStateChanged 管理登录状态,在服务端验证令牌;不要在没有验证的情况下信任客户端声明。
限制与缺失信息:资料未提供具体收费、价格、平台支持细节、速率限制或配额信息,这些方面暂未提供,需参考 Firebase 官方文档确认。