Getting Started
复制一个带有安装步骤和完整 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.
安装
标题为“安装”您可以使用我们的 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-authenticationbunx cap syncimport { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';API概述
名为“API概述”的部分applyActionCode
名为“applyActionCode”的部分发送到用户邮箱的验证code
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.applyActionCode({} as ApplyActionCodeOptions);confirmPasswordReset
确认密码重置完成密码重置
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.confirmPasswordReset({} as ConfirmPasswordResetOptions);confirmVerificationCode
确认验证码完成手机验证
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.confirmVerificationCode({} as ConfirmVerificationCodeOptions);createUserWithEmailAndPassword
创建用户帐户创建新用户帐户并自动登录
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.createUserWithEmailAndPassword({} as CreateUserWithEmailAndPasswordOptions);deleteUser
复制到剪贴板__CAPGO_KEEP_0__
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.deleteUser();fetchSignInMethodsForEmail
《fetchSignInMethodsForEmail》获取指定邮箱地址的登录方式
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.fetchSignInMethodsForEmail({} as FetchSignInMethodsForEmailOptions);getCurrentUser
《getCurrentUser》获取当前登录用户
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.getCurrentUser();getPendingAuthResult
《getPendingAuthResult》返回 SignInResult 如果您的应用启动了一个Web登录流程,且在后台时操作系统清理了应用程序
仅适用于Android
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.getPendingAuthResult();getIdToken
标题:获取 ID 令牌获取 Firebase Auth ID 令牌,用于当前已登录的用户。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.getIdToken();getIdTokenResult
标题:获取 ID 令牌结果返回一个用于识别用户的 JSON Web 令牌 (JWT),用于 Firebase 服务。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.getIdTokenResult();getRedirectResult
标题:获取重定向结果返回重定向式登录流程中的 SignInResult 如果登录失败,则以错误形式返回。如果未调用重定向操作,则返回一个
用户为 null SignInResult 复制到剪贴板
只适用于 Web。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.getRedirectResult();getTenantId
标题:"getTenantId"获取租户 ID。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.getTenantId();isSignInWithEmailLink
标题:"isSignInWithEmailLink"检查是否有一个 incoming 链接是适合用于 signInWithEmailLink.
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.isSignInWithEmailLink({} as IsSignInWithEmailLinkOptions);linkWithApple
标题:"linkWithApple"将用户帐户与 Apple 身份验证提供商关联。
用户必须在原生层上登录。
skipNativeAuth 此配置选项在这里无效。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.linkWithApple();linkWithEmailAndPassword
标题:《linkWithEmailAndPassword》将用户帐户与电子邮件身份验证提供者关联。
用户必须在原生层上登录。
skipNativeAuth 此配置选项在此处无效。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.linkWithEmailAndPassword({} as LinkWithEmailAndPasswordOptions);linkWithEmailLink
标题:《linkWithEmailLink》将用户帐户与电子邮件身份验证提供者关联。
用户必须在原生层上登录。
skipNativeAuth 此配置选项在此处无效。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.linkWithEmailLink({} as LinkWithEmailLinkOptions);linkWithFacebook
标题:《linkWithFacebook》将用户账户与Facebook认证提供者关联.
用户必须在原生层上登录。
配置选项在此处无效. skipNativeAuth 复制到剪贴板
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.linkWithFacebook();linkWithGameCenter
将用户账户与Game Center认证提供者关联.用户必须在原生层上登录。 配置选项在此处无效.
仅适用于iOS. skipNativeAuth 复制到剪贴板
标题:linkWithGithub
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.linkWithGameCenter();linkWithGithub
]} Links the user account with GitHub authentication provider.
用户必须在原生层上登录。 skipNativeAuth 此配置选项在这里无效。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.linkWithGithub();linkWithGoogle
标题: "linkWithGoogle"将用户帐户与 Google 身份验证提供者关联。
用户必须在原生层上登录。 skipNativeAuth 此配置选项在这里无效。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.linkWithGoogle();linkWithMicrosoft
标题: "linkWithMicrosoft"将用户帐户与 Microsoft 身份验证提供者关联。
用户必须在原生层上登录。 skipNativeAuth 此配置选项在这里无效。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.linkWithMicrosoft();linkWithOpenIdConnect
标题:linkWithOpenIdConnect使用 OpenID Connect 提供者链接用户帐户。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.linkWithOpenIdConnect({} as LinkWithOpenIdConnectOptions);linkWithPhoneNumber
标题:linkWithPhoneNumber使用电话号码身份验证提供者链接用户帐户。
用户必须在原生层上登录。
skipNativeAuth 此配置选项在这里无效。
使用 phoneVerificationCompleted 监听器来接收验证完成的通知。
使用 phoneVerificationFailed 监听器来接收验证失败的通知。
使用 phoneCodeSent 监听器来获取验证 ID。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.linkWithPhoneNumber({} as LinkWithPhoneNumberOptions);linkWithPlayGames
标题:《linkWithPlayGames》将用户账户与Play Games身份验证提供者关联。
用户必须在原生层上登录。
skipNativeAuth 此配置选项在此处无效。
仅适用于Android。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.linkWithPlayGames();linkWithTwitter
标题:《linkWithTwitter》将用户账户与Twitter身份验证提供者关联。
用户必须在原生层上登录。
skipNativeAuth 此配置选项在此处无效。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.linkWithTwitter();linkWithYahoo
Section titled “linkWithYahoo”与 Yahoo 身份验证提供者关联用户账户。
用户必须在原生层上登录。
skipNativeAuth 此配置选项在此处无效。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.linkWithYahoo();reload
Section titled “reload”重新加载用户账户数据,如果已登录。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.reload();revokeAccessToken
Section titled “revokeAccessToken”撤销指定的访问令牌。目前仅支持 Apple OAuth 访问令牌。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.revokeAccessToken({} as RevokeAccessTokenOptions);sendEmailVerification
Section titled “sendEmailVerification”发送验证码邮件到当前已登录用户。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.sendEmailVerification();sendPasswordResetEmail
标题:“sendPasswordResetEmail”发送密码重置邮件。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.sendPasswordResetEmail({} as SendPasswordResetEmailOptions);sendSignInLinkToEmail
标题:“sendSignInLinkToEmail”向指定邮箱的用户发送登录邮件链接。
要完成使用邮箱链接登录,请调用 signInWithEmailLink 使用邮箱地址和邮箱链接(在发送给用户的邮件中提供)
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.sendSignInLinkToEmail({} as SendSignInLinkToEmailOptions);setLanguageCode
标题:“setLanguageCode”设置用户界面语言code用于身份验证操作。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.setLanguageCode({} as SetLanguageCodeOptions);setPersistence
标题:设置持久性设置当前保存的认证会话的持久性类型。
仅适用于Web。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.setPersistence({} as SetPersistenceOptions);setTenantId
标题:设置租户ID设置租户ID。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.setTenantId({} as SetTenantIdOptions);signInAnonymously
标题:匿名登录作为匿名用户登录。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInAnonymously();signInWithApple
标题:使用Apple登录启动 Apple 登录流程。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithApple();signInWithCustomToken
signInWithCustomToken 部分启动自定义令牌登录流程。
此方法不能与 skipNativeAuth 在 Android 和 iOS 上使用。
在这种情况下,您必须使用 signInWithCustomToken 接口直接使用 Firebase JS SDK。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithCustomToken({} as SignInWithCustomTokenOptions);signInWithEmailAndPassword
signInWithEmailAndPassword 部分使用电子邮件和密码启动登录流程。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithEmailAndPassword({} as SignInWithEmailAndPasswordOptions);signInWithEmailLink
signInWithEmailLink 部分使用电子邮件和登录电子邮件链接登录。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithEmailLink({} as SignInWithEmailLinkOptions);signInWithFacebook
标题:"signInWithFacebook"启动Facebook登录流程。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithFacebook();signInWithGameCenter
标题:"signInWithGameCenter"启动Game Center登录流程。
仅适用于iOS。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithGameCenter();signInWithGithub
标题:"signInWithGithub"启动GitHub登录流程。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithGithub();signInWithGoogle
Section titled “Google 登录”开始 Google 登录流程。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithGoogle();signInWithMicrosoft
Section titled “Microsoft 登录”开始 Microsoft 登录流程。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithMicrosoft();signInWithOpenIdConnect
Section titled “OpenID Connect 登录”开始 OpenID Connect 登录流程。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithOpenIdConnect({} as SignInWithOpenIdConnectOptions);signInWithPhoneNumber
Section titled “手机号登录”使用手机号开始登录流程。
使用 phoneVerificationCompleted 当验证完成时,通知此监听器。
使用 phoneVerificationFailed 当验证失败时,通知此监听器。
使用 phoneCodeSent 获取验证ID的监听器。
仅适用于Android和iOS.
复制到剪贴板
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithPhoneNumber({} as SignInWithPhoneNumberOptions);signInWithPlayGames
启动Play Games登录流程。
仅适用于Android.复制到剪贴板
标题:"signInWithTwitter"
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithPlayGames();signInWithTwitter
标题:"signInWithApple"启动Apple登录流程。 仅适用于iOS。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithTwitter();signInWithYahoo
yahoo登入流程开始yahoo登入流程
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithYahoo();signOut
登出开始登出流程
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signOut();unlink
解绑解绑服务提供商
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.unlink({} as UnlinkOptions);updateEmail
更新当前登入用户的电子邮件地址复制到剪贴板']}
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.updateEmail({} as UpdateEmailOptions);updatePassword
Section titled “updatePassword”更新当前已登录用户的密码。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.updatePassword({} as UpdatePasswordOptions);updateProfile
Section titled “updateProfile”更新用户的资料。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.updateProfile({} as UpdateProfileOptions);useAppLanguage
Section titled “useAppLanguage”设置用户面向的语言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({} as UseEmulatorOptions);verifyBeforeUpdateEmail
Section titled “verifyBeforeUpdateEmail”在更新当前登录用户的电子邮件地址之前,验证新电子邮件地址。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.verifyBeforeUpdateEmail({} as VerifyBeforeUpdateEmailOptions);checkAppTrackingTransparencyPermission
Section titled “checkAppTrackingTransparencyPermission”检查当前应用跟踪透明度的状态。
仅在 iOS 上可用。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.checkAppTrackingTransparencyPermission();requestAppTrackingTransparencyPermission
Section titled “requestAppTrackingTransparencyPermission”打开系统对话框,授权应用跟踪透明度。
注意: 用户可能在设备设置中禁用了跟踪请求,请参阅 Apple 的文档.
仅在 iOS 上可用。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.requestAppTrackingTransparencyPermission();类型参考
类型参考部分ApplyActionCodeOptions
应用代码操作选项部分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
获取电子邮件登录方法结果export 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
获取当前用户结果export interface GetCurrentUserResult { /** * The currently signed-in user, or null if there isn't any. * * @since 0.1.0 */ user: User | null;}GetIdTokenOptions
获取 ID 令牌选项export interface GetIdTokenOptions { /** * Force refresh regardless of token expiration. * * @since 0.1.0 */ forceRefresh: boolean;}GetIdTokenResult
获取 ID 令牌结果export interface GetIdTokenResult { /** * The Firebase Auth ID token JWT string. * * @since 0.1.0 */ token: string;}GetIdTokenResultOptions
Section titled “GetIdTokenResultOptions”export interface GetIdTokenResultOptions { /** * Force refresh regardless of token expiration. * * @since 7.4.0 */ forceRefresh: boolean;}GetIdTokenResultResult
Section titled “GetIdTokenResultResult”export 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>;}真实数据来源
Section titled “真实数据来源”本页面由插件生成 src/definitions.ts当公共 API 上游更改时,请重新同步。
继续从 Getting Started
Section titled “继续从 Getting Started”如果您正在使用 Getting Started 为了计划身份验证和帐户流程,连接它与 @capgo/capacitor-social-login 关于@capgo/capacitor-social-login的实现细节在 @capgo/capacitor-passkey 关于@capgo/capacitor-passkey的实现细节在 @capgo/capacitor-native-biometric 关于@capgo/capacitor-native-biometric的实现细节在 双因素身份验证 关于双因素身份验证的实现细节在 企业SSO 关于企业SSO的实现细节在