Page/area: Capgo marketing website. Role: Website copy sentence. Seen in: component doc/SignupCta.astro, component Hero.astro. Message key `hero_subtitle_v2` (Hero Subtitle V2).
复制一个包含安装步骤和本插件的完整Markdown指南的设置提示。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-firebase-authentication`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/firebase-authentication/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
Install
准备粘贴的内容了!您可以使用我们的AI辅助设置来安装插件。使用以下命令将Capgo技能添加到您的AI工具中:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下提示:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-firebase-authentication` plugin in my project.如果您更喜欢手动设置,请运行以下命令并按照以下平台特定的说明进行操作:
bun add @capgo/capacitor-firebase-authenticationnpx cap sync导入
导入import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';快速入门
快速入门import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.applyActionCode({ oobCode: 'oob-code' });Live Update
Example: confirmPasswordResetimport { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.confirmPasswordReset({ oobCode: 'oob-code', newPassword: 'new-password',});Example: confirmPasswordReset
Example: confirmVerificationCodeimport { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.confirmVerificationCode({ verificationId: 'phoneCodeSent', verificationCode: 'phoneCodeSent',});// The result holds sensitive values: use it without logging it.Example: confirmVerificationCode
常见问题- Listeners移除屏幕卸载时的句柄。
- 原生同步: run
npx cap sync: run - 真实数据来源: trust
src/definitions.ts在 GitHub repo 中的真实来源
API Capgo概览
API OverviewapplyActionCode
应用ActionCodeApplies a verification code sent to the user by email.
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.applyActionCode({ oobCode: 'oob-code' });confirmPasswordReset
复制到剪贴板完成密码重置过程。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.confirmPasswordReset({ oobCode: 'oob-code', newPassword: 'new-password',});confirmVerificationCode
确认验证码完成手机验证过程。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.confirmVerificationCode({ verificationId: 'phoneCodeSent', verificationCode: 'phoneCodeSent',});// The result holds sensitive values: use it without logging it.createUserWithEmailAndPassword
创建用户帐户删除用户
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.createUserWithEmailAndPassword({ email: 'user@example.com', password: 'password',});// The result holds sensitive values: use it without logging it.deleteUser
删除用户并注销获取用户邮箱的登录方式
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.deleteUser();fetchSignInMethodsForEmail
__CAPGO_KEEP_0__获取指定电子邮件地址的登录方法。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.fetchSignInMethodsForEmail({ email: 'user@example.com' });console.log(result);getCurrentUser
获取当前用户获取当前已登录用户
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.getCurrentUser();// The result holds sensitive values: use it without logging it.getPendingAuthResult
获取等待验证结果返回结果 SignInResult 仅适用于 Android
获取 Firebase Auth ID Token
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.getPendingAuthResult();// The result holds sensitive values: use it without logging it.getIdToken
获取 Firebase Auth ID Token获取 Firebase Auth ID Token
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.getIdToken();// The result holds sensitive values: use it without logging it.getIdTokenResult
标题:获取 ID 令牌结果返回一个用来标识用户并向 Firebase 服务进行身份验证的 JSON Web 令牌 (JWT)。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.getIdTokenResult();// The result holds sensitive values: use it without logging it.getRedirectResult
标题:获取重定向结果返回重定向式登录流中的 SignInResult 如果登录失败,则失败并返回错误。如果没有调用重定向操作,则返回一个
用户为 null 的 SignInResult 仅适用于 Web。
标题:获取租户 ID
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.getRedirectResult();// The result holds sensitive values: use it without logging it.getTenantId
__CAPGO_KEEP_0__获取租户 ID。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.getTenantId();console.log(result);isSignInWithEmailLink
电子邮件链接登录检查是否为电子邮件链接登录 signInWithEmailLink.
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.isSignInWithEmailLink({ emailLink: 'https://example.com' });// The result holds sensitive values: use it without logging it.linkWithApple
Apple 链接与 Apple 进行绑定
用户必须在原生层上登录。
此配置选项在此处无效。 skipNativeAuth 电子邮件链接
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.linkWithApple();// The result holds sensitive values: use it without logging it.linkWithEmailAndPassword
与电子邮件进行绑定与电子邮件进行绑定
用户必须在原生层上登录。
skipNativeAuth 此配置选项在这里无效。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.linkWithEmailAndPassword({ email: 'user@example.com', password: 'password',});// The result holds sensitive values: use it without logging it.linkWithEmailLink
使用电子邮件链接标题为“linkWithEmailLink”
用户必须在原生层上登录。
skipNativeAuth 此配置选项在这里无效。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.linkWithEmailLink({ email: 'user@example.com', emailLink: 'https://example.com',});// The result holds sensitive values: use it without logging it.linkWithFacebook
将用户帐户与电子邮件身份验证提供者关联。标题为“linkWithFacebook”
用户必须在原生层上登录。
skipNativeAuth 此配置选项在这里无效。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.linkWithFacebook();// The result holds sensitive values: use it without logging it.linkWithGameCenter
Game Center链接用户账户与Game Center身份验证提供者
用户必须在原生层上登录 skipNativeAuth 此配置选项在此处无效
仅适用于iOS
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.linkWithGameCenter();// The result holds sensitive values: use it without logging it.linkWithGithub
GitHub链接用户账户与GitHub身份验证提供者
用户必须在原生层上登录 skipNativeAuth 此配置选项在此处无效
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.linkWithGithub();// The result holds sensitive values: use it without logging it.linkWithGoogle
Section titled “Google 链接”将用户账户与 Google 身份验证提供者链接。
用户必须在原生层上登录。
skipNativeAuth 此配置选项在此处无效。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.linkWithGoogle();// The result holds sensitive values: use it without logging it.linkWithMicrosoft
Section titled “Microsoft 链接”将用户账户与 Microsoft 身份验证提供者链接。
用户必须在原生层上登录。
skipNativeAuth 此配置选项在此处无效。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.linkWithMicrosoft();// The result holds sensitive values: use it without logging it.linkWithOpenIdConnect
Section titled “OpenID Connect 链接”将用户账户与 OpenID Connect 提供者链接。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.linkWithOpenIdConnect({ providerId: 'provider-id-123' });// The result holds sensitive values: use it without logging it.linkWithPhoneNumber
标题:linkWithPhoneNumber将用户帐户与电话号码验证提供程序关联。
用户必须在原生层上登录。 skipNativeAuth 配置选项在此处无效。
使用 phoneVerificationCompleted 监听器来接收验证完成的通知。 phoneVerificationFailed 使用 phoneCodeSent 监听器来接收验证失败的通知。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.linkWithPhoneNumber({ phoneNumber: "+16505550101" });linkWithPlayGames
使用监听器来获取验证ID。
用户必须在原生层上登录。
skipNativeAuth 此配置选项在此处无效。
仅适用于 Android。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.linkWithPlayGames();// The result holds sensitive values: use it without logging it.linkWithTwitter
标题:linkWithTwitter将用户账户与 Twitter 身份验证提供者关联。
用户必须在原生层上登录。
skipNativeAuth 此配置选项在此处无效。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.linkWithTwitter();// The result holds sensitive values: use it without logging it.linkWithYahoo
标题:linkWithYahoo将用户账户与 Yahoo 身份验证提供者关联。
用户必须在原生层上登录。
skipNativeAuth 配置选项在这里无效。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.linkWithYahoo();// The result holds sensitive values: use it without logging it.reload
重新加载重新加载用户帐户数据,如果已登录。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.reload();revokeAccessToken
撤销访问令牌撤销给定的访问令牌。目前仅支持Apple OAuth访问令牌。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.revokeAccessToken({ token: 'token-123' });sendEmailVerification
发送验证邮件发送验证邮件到当前已登录用户。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.sendEmailVerification();sendPasswordResetEmail
发送密码重置邮件发送密码重置邮件。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.sendPasswordResetEmail({ email: 'user@example.com' });sendSignInLinkToEmail
发送登录链接到邮箱发送指定邮箱的登录链接给用户。
使用以下代码完成电子邮件链接登录 signInWithEmailLink To complete sign in with the email link, call
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.sendSignInLinkToEmail({ email: 'user@example.com', actionCodeSettings: { url: 'https://example.com' },});setLanguageCode
设置用户面向的语言设置用户可见的语言code用于认证操作。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.setLanguageCode({ languageCode: "en-US" });setPersistence
设置当前保存的认证会话的持久性类型Section titled “setPersistence”
仅适用于 Web。
import { FirebaseAuthentication, Persistence } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.setPersistence({ persistence: Persistence.IndexedDbLocal });setTenantId
设置租户 ID设置租户 ID
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.setTenantId({ tenantId: 'tenant-id-123' });signInAnonymously
匿名用户登录开始 Apple 登录流程
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.signInAnonymously();// The result holds sensitive values: use it without logging it.signInWithApple
使用自定义令牌登录使用自定义令牌登录
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.signInWithApple();// The result holds sensitive values: use it without logging it.signInWithCustomToken
使用自定义令牌登录开始自定义令牌登录流程。
此方法不能与 skipNativeAuth 在 Android 和 iOS 上使用。
在这种情况下,您必须使用 Firebase JS __CAPGO_KEEP_0__ 的 signInWithCustomToken interface of the Firebase JS SDK directly.
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.signInWithCustomToken({ token: 'token-123' });// The result holds sensitive values: use it without logging it.signInWithEmailAndPassword
使用电子邮件和密码启动登录流程。标题:signInWithEmailLink
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.signInWithEmailAndPassword({ email: 'user@example.com', password: 'password',});// The result holds sensitive values: use it without logging it.signInWithEmailLink
使用电子邮件和登录电子邮件链接启动登录流程。标题:signInWithFacebook
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.signInWithEmailLink({ email: 'user@example.com', emailLink: 'https://example.com',});// The result holds sensitive values: use it without logging it.signInWithFacebook
标题:signInWithApple开始 Facebook 登录流程。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.signInWithFacebook();// The result holds sensitive values: use it without logging it.signInWithGameCenter
游戏中心仅限 iOS
GitHub
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.signInWithGameCenter();// The result holds sensitive values: use it without logging it.signInWithGithub
开始 __CAPGO_KEEP_0__ 登录流程。启动GitHub登录流程。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.signInWithGithub();// The result holds sensitive values: use it without logging it.signInWithGoogle
开始 Google 登录流程。复制到剪贴板
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.signInWithGoogle();// The result holds sensitive values: use it without logging it.signInWithMicrosoft
Microsoft 登录流程启动 Microsoft 登录流程
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.signInWithMicrosoft();// The result holds sensitive values: use it without logging it.signInWithOpenIdConnect
OpenID Connect 登录流程手机号登录流程
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.signInWithOpenIdConnect({ providerId: 'provider-id-123' });// The result holds sensitive values: use it without logging it.signInWithPhoneNumber
使用监听完成验证
监听验证失败 phoneVerificationCompleted 获取验证 ID phoneVerificationFailed 获取验证 ID phoneCodeSent 获取验证 ID
仅适用于 Android 和 iOS。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithPhoneNumber({ phoneNumber: "+16505550101" });signInWithPlayGames
signInWithPlayGames开始 Play Games 登录流程。
仅适用于 Android。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.signInWithPlayGames();// The result holds sensitive values: use it without logging it.signInWithTwitter
signInWithTwitter开始 Twitter 登录流程。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.signInWithTwitter();// The result holds sensitive values: use it without logging it.signInWithYahoo
signInWithYahoo开始 Yahoo 登录流程。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.signInWithYahoo();// The result holds sensitive values: use it without logging it.signOut
Section titled “登出”开始登出流程。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signOut();unlink
context解除用户账户与服务提供者的绑定。
import { FirebaseAuthentication, ProviderId } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.unlink({ providerId: ProviderId.APPLE });// The result holds sensitive values: use it without logging it.updateEmail
Section titled “解绑”解除用户账户与提供者的绑定。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.updateEmail({ newEmail: 'user@example.com' });updatePassword
Section titled “更新电子邮件”更新当前登录用户的电子邮件地址。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.updatePassword({ newPassword: 'new-password' });updateProfile
更新资料更新用户资料
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.updateProfile({ displayName: 'display', photoUrl: 'https://example.com',});useAppLanguage
context设置用户界面语言code为应用的默认语言。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.useAppLanguage();useEmulator
设置应用语言Section titled “useEmulator”
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.useEmulator({ host: "127.0.0.1" });verifyBeforeUpdateEmail
使用模拟器Section titled “verifyBeforeUpdateEmail”
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.verifyBeforeUpdateEmail({ newEmail: 'user@example.com' });checkAppTrackingTransparencyPermission
Section titled “检查App跟踪透明度权限”检查当前App跟踪透明度状态。
仅适用于iOS。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.checkAppTrackingTransparencyPermission();console.log(result);requestAppTrackingTransparencyPermission
context打开系统对话框,授权应用跟踪透明度。
Attention: 打开系统对话框,授权App跟踪透明度。 注意:.
仅适用于iOS。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
const result = await FirebaseAuthentication.requestAppTrackingTransparencyPermission();console.log(result);用户可能在设备设置中禁用了跟踪请求,请参见“Apple的文档”中的说明。
类型参考ApplyActionCodeOptions
应用ActionCode选项export interface ApplyActionCodeOptions { /** * A verification code sent to the user. * * @since 0.2.2 */ oobCode: string;}ConfirmPasswordResetOptions
确认密码重置选项export interface ConfirmPasswordResetOptions { /** * A verification code sent to the user. * * @since 0.2.2 */ oobCode: string; /** * The new password. * * @since 0.2.2 */ newPassword: string;}ConfirmVerificationCodeOptions
确认验证码选项export interface ConfirmVerificationCodeOptions { /** * The verification ID received from the `phoneCodeSent` listener. * * The `verificationCode` option must also be provided. * * @since 5.0.0 */ verificationId: string; /** * The verification code either received from the `phoneCodeSent` listener or entered by the user. * * The `verificationId` option must also be provided. * * @since 5.0.0 */ verificationCode: string;}SignInResult
登录结果export interface SignInResult { /** * The currently signed-in user, or null if there isn't any. * * @since 0.1.0 */ user: User | null; /** * Credentials returned by an auth provider. * * @since 0.1.0 */ credential: AuthCredential | null; /** * Additional user information from a federated identity provider. * * @since 0.5.1 */ additionalUserInfo: AdditionalUserInfo | null;}CreateUserWithEmailAndPasswordOptions
创建用户帐户选项export interface CreateUserWithEmailAndPasswordOptions { /** * @since 0.2.2 */ email: string; /** * @since 0.2.2 */ password: string;}FetchSignInMethodsForEmailOptions
获取电子邮件帐户登录方法选项export interface FetchSignInMethodsForEmailOptions { /** * The user's email address. * * @since 6.0.0 */ email: string;}FetchSignInMethodsForEmailResult
FetchSignInMethodsForEmailResultexport interface FetchSignInMethodsForEmailResult { /** * The sign-in methods for the specified email address. * * This list is empty when [Email Enumeration Protection](https://cloud.google.com/identity-platform/docs/admin/email-enumeration-protection) * is enabled, irrespective of the number of authentication methods available for the given email. * * @since 6.0.0 */ signInMethods: string[];}GetCurrentUserResult
GetCurrentUserResultexport interface GetCurrentUserResult { /** * The currently signed-in user, or null if there isn't any. * * @since 0.1.0 */ user: User | null;}GetIdTokenOptions
GetIdTokenOptionsexport interface GetIdTokenOptions { /** * Force refresh regardless of token expiration. * * @since 0.1.0 */ forceRefresh: boolean;}GetIdTokenResult
GetIdTokenResultexport interface GetIdTokenResult { /** * The Firebase Auth ID token JWT string. * * @since 0.1.0 */ token: string;}GetIdTokenResultOptions
GetIdTokenResultOptionsexport interface GetIdTokenResultOptions { /** * Force refresh regardless of token expiration. * * @since 7.4.0 */ forceRefresh: boolean;}GetIdTokenResultResult
GetIdTokenResultResultexport interface GetIdTokenResultResult { /** * The authentication time in milliseconds since the epoch. * * This is the time the user authenticated (signed in) and not the time the token was refreshed. * * @since 7.4.0 */ authTime: number; /** * The ID token expiration time in milliseconds since the epoch. * * @since 7.4.0 */ expirationTime: number; /** * The ID token issuance time in milliseconds since the epoch. * * @since 7.4.0 */ issuedAtTime: number; /** * The sign-in provider through which the ID token was obtained. * * @since 7.4.0 */ signInProvider: string | null; /** * The type of second factor associated with this session, provided the user was multi-factor * authenticated (eg. phone, etc). * * @since 7.4.0 */ signInSecondFactor: string | null; /** * The entire payload claims of the ID token including the standard reserved claims as well as * the custom claims. * * @since 7.4.0 */ claims: Record<string, unknown>;}真实来源
源头本页面是由插件的 src/definitions.ts重新同步公共API时,API发生了变化。
继续从开始
源头如果您正在使用 开始 来规划身份验证和帐户流程,连接它与 @capgo/capacitor-社交登录 查看@capgo/capacitor-social-login的实现细节 @capgo/capacitor-passkey 为 @capgo/capacitor-passkey 的实现细节 @capgo/capacitor-native-biometric 为 @capgo/capacitor-native-biometric 的实现细节 双因素认证 为双因素认证和 SSO (企业) 为 SSO (企业) 的实现细节