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.如果您prefer手动设置,安装插件并运行以下命令并遵循以下平台特定的说明:
bun add @capgo/capacitor-firebase-authenticationbunx cap syncimport { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';API 介绍
标题:API 介绍applyActionCode
标题:applyActionCodeApplies a verification code sent to the user by email.
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.applyActionCode({} as ApplyActionCodeOptions);confirmPasswordReset
标题:confirmPasswordReset完成密码重置
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.confirmPasswordReset({} as ConfirmPasswordResetOptions);confirmVerificationCode
标题:confirmVerificationCode完成手机验证码验证
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.confirmVerificationCode({} as ConfirmVerificationCodeOptions);createUserWithEmailAndPassword
标题:createUserWithEmailAndPassword创建一个新的用户帐户,使用电子邮件和密码。 如果新帐户创建成功,用户会自动登录。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.createUserWithEmailAndPassword({} as CreateUserWithEmailAndPasswordOptions);deleteUser
标题:删除用户删除用户并注销。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.deleteUser();fetchSignInMethodsForEmail
标题:获取电子邮件地址的登录方式获取电子邮件地址的登录方式。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.fetchSignInMethodsForEmail({} as FetchSignInMethodsForEmailOptions);getCurrentUser
标题:获取当前登录用户获取当前登录用户。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.getCurrentUser();getPendingAuthResult
标题:获取待处理的认证结果返回值 SignInResult 如果您的应用程序在后台启动了一个 web 登录流程,且操作系统在清理应用程序时,应用程序会被清除。
仅适用于 Android。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.getPendingAuthResult();getIdToken
标题:getIdToken获取 Firebase Auth ID Token,用于当前已登录用户。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.getIdToken();getIdTokenResult
标题:getIdTokenResult返回一个用于识别用户的 Firebase 服务的 JSON Web Token (JWT)。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.getIdTokenResult();getRedirectResult
标题:getRedirectResult返回值 SignInResult 从重定向基于登录流程。
如果登录失败,会失败并返回一个错误。
如果没有调用重定向操作,返回一个 SignInResult 用户为 null 的
仅适用于 Web。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.getRedirectResult();getTenantId
标题为“获取租户 ID”获取租户 ID。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.getTenantId();isSignInWithEmailLink
标题为“检查是否为电子邮件链接登录”检查一个 incoming 链接是否是适合的电子邮件登录链接 signInWithEmailLink.
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.isSignInWithEmailLink({} as IsSignInWithEmailLinkOptions);linkWithApple
标题为“与 Apple 链接”与 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
标题:“linkWithGameCenter”将用户帐户与Game Center身份验证提供者链接。
用户必须在原生层上登录。
skipNativeAuth 此配置选项在此处无效。
仅适用于iOS。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.linkWithGameCenter();linkWithGithub
标题:“linkWithGithub”将用户帐户与GitHub身份验证提供者关联。
用户必须在原生层上登录。
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
标题:linkWithYahoo将用户账户与 Yahoo 身份验证提供者关联。
用户必须在原生层上登录。
skipNativeAuth 此配置选项在这里无效。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.linkWithYahoo();reload
标题:reload重新加载用户账户数据,如果已登录。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.reload();revokeAccessToken
标题:revokeAccessToken撤销指定的访问令牌。目前仅支持 Apple OAuth 访问令牌。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.revokeAccessToken({} as RevokeAccessTokenOptions);sendEmailVerification
标题:“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
标题:设置语言代码设置用户界面语言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
标题:signInWithApple启动Apple登录流程。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithApple();signInWithCustomToken
标题:signInWithCustomToken启动自定义令牌登录流程。
此方法不能与 skipNativeAuth 在Android和iOS上使用。
在这种情况下,您必须使用Firebase JS __CAPGO_KEEP_0__的接口。 signInWithCustomToken interface of the Firebase JS SDK directly.
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithCustomToken({} as SignInWithCustomTokenOptions);signInWithEmailAndPassword
protectedTokens使用电子邮件和密码启动登录流程。
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
GitHub 登录开始GitHub登录流程。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithGithub();signInWithGoogle
Google 登录开始 Google 登录流程。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithGoogle();signInWithMicrosoft
Microsoft 登录开始 Microsoft 登录流程。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithMicrosoft();signInWithOpenIdConnect
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
Section titled “Play Games 登录”启动 Play Games 登录流程。
仅适用于 Android。
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithPlayGames();signInWithTwitter
Twitter 登录开始 Twitter 登录流程。
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
Section titled “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”Sets the user-facing language code to be the default app language.
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”打开系统对话框以授权应用程序跟踪透明度。
注意: 用户可能在设备设置中禁用了跟踪请求,见 苹果的文档.
仅在 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
标题:“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
标题:“CreateUserWithEmailAndPasswordOptions”export interface CreateUserWithEmailAndPasswordOptions { /** * @since 0.2.2 */ email: string; /** * @since 0.2.2 */ password: string;}FetchSignInMethodsForEmailOptions
标题:“FetchSignInMethodsForEmailOptions”export interface FetchSignInMethodsForEmailOptions { /** * The user's email address. * * @since 6.0.0 */ email: string;}FetchSignInMethodsForEmailResult
标题:“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
标题:“GetCurrentUserResult”export interface GetCurrentUserResult { /** * The currently signed-in user, or null if there isn't any. * * @since 0.1.0 */ user: User | null;}GetIdTokenOptions
标题:“GetIdTokenOptions”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
标题:获取 ID 令牌结果选项export interface GetIdTokenResultOptions { /** * Force refresh regardless of token expiration. * * @since 7.4.0 */ forceRefresh: boolean;}GetIdTokenResultResult
标题:获取 ID 令牌结果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>;}真实来源
标题:真实来源本页面由插件生成 src/definitions.ts当公共 API 在上游发生变化时,请重新同步。
继续从 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 (企业版) 的实现细节。