@capacitor-firebase/authentication

中文文档
8.6.0发布于 2026/10/31Apache-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 63.6万

在Android,iOS,和Web上用于Firebase认证的电容插件.

中文使用文档
文档目录92 节
  1. 使用大小写
  2. 兼容性
  3. 指南
  4. 安装
  5. iOS系统
  6. 配置
  7. 实例
  8. 火基地 JavaScript SDK
  9. 演示
  10. 启动模板
  11. 使用量
  12. 签名并用电子邮件和密码签名
  13. 跟社工签约
  14. 用电话号码签名
  15. 用电子邮件链接签名
  16. 匿名签名
  17. 用自定义的符号或 OpenID 连接签名
  18. 获取当前用户和标识符
  19. 发送和确认密码重置
  20. 校验用户的电子邮件地址
  21. 更新用户的电子邮件或密码
  22. 查找电子邮件的登录方法
  23. 设置语言
  24. 签名并删除用户
  25. 使用火地模拟器
  26. API 密码
  27. 应用动作代码(...)
  28. 确认 Password 重置(...)
  29. 确认验证码(...)
  30. 创建 UserWith EmailAndPassword (.)
  31. 删除用户( )
  32. 获取 SignInMethods ForEmail (...)
  33. 获取当前用户( C)
  34. 获得PendingAuthResult ()
  35. 获取 IdToken (...)
  36. 获取 IdToken Result (...)
  37. 获取直接结果( C)
  38. 获取 TenantId ()
  39. 是SignIn With EmailLink (...) 的缩写
  40. 链接与 Apple (...)
  41. 链接与电子邮件AndPassword (...)
  42. 链接与电子邮件链接(...)
  43. 链接到脸书(...)
  44. 链接到 GameCenter (...)
  45. 链接到 Github (...)
  46. 链接到 Google (...)
  47. 链接微软(...)
  48. 链接与 OpenIdConnect (...)
  49. 链接与 Phone 数字(...)
  50. 链接与 PlayGames (...)
  51. 链接到 Twitter (...)
  52. 链接与 Yahoo (...)
  53. 重新装入( c)
  54. 撤销 AccessToken (...)
  55. 发送电子邮件验证(...)
  56. 发送 Password 重置邮件(...)
  57. 发送SignInLink To电子邮件(...)
  58. 语言代码(...)
  59. 设置持续(...)
  60. 设置 TenantId (...)
  61. 匿名签名 ()
  62. 签名InWithApple (...)
  63. 签名 InWithCustom Token (...)
  64. 在电子邮件中签名 AndPassword (...)
  65. 在电子邮件链接中签名(...)
  66. 使用脸书签名(...)
  67. 签入 Game 中心(...)
  68. 签名 InWithub (...)
  69. 使用 Google 签名(...)
  70. 签名InWith Microsoft (...)
  71. 在 OpenIdConnect 中签名(...)
  72. 签名 InWithPhone 数字(...)
  73. 签入 PlayGames (...)
  74. 签名 With Twitter (...)
  75. 签入 Yahoo (...)
  76. 符号输出( C)
  77. 取消链接(...)
  78. 更新电子邮件(...)
  79. 更新 Password (.)
  80. 更新Profile (...)
  81. 使用 AppLangage () 语言
  82. 使用计算器(...)
  83. 校验更新前的电子邮件(...)
  84. 追踪透明性
  85. 追踪透明性
  86. 添加倾听器( “ 自动状态变化 ” ,...)
  87. 添加倾听器( “ id TokenChange ” ,...)
  88. 添加聆听器( “ 手机验证完成 ” ,...)
  89. 添加倾听器( “ 电话验证失败 ” ,...)
  90. 添加倾听器( “ 手机代码Sent' ,...)
  91. 删除所有收听器( )
  92. 接口

电容火库认证插件

非官方电容插件 Firebase 验证[^1]

使用大小写

Firebase认证插件一般用于处理一个应用程序的整个登录入流,例如:

  • 社会登录:在本地用户中与Apple,Google,Facebook,微软,GitHub,Twitter,Yahoo,Play Games,或Game Center签名.
  • 基于电子邮件的认证:用电子邮件和密码在用户中注册和签名,或发给他们无密码的登录链接.
  • 电话号码登录:用发送到电话号码的短信码验证用户.
  • 来宾出入: 让用户用匿名签名尝试您的应用程序, 并在稍后链接一个永久账户 .
  • 自定义后端:用自定义的符号或OpenID Connection签名并取回ID符来认证请求到自己的后端.

兼容性

插件版本电容版本状态
8.x.x (英语)>=8.x.x积极支持
7.x.x (中文(简体) )7.x.x (中文(简体) )折旧
6.x.x (中文(简体) )6.x.x (中文(简体) )折旧
5.x.x (中文(简体) )5.x.x (中文(简体) )折旧
1.x.x (中文(简体) )4.x.x (中文(简体) )折旧

指南

安装

你可以用我们的 AI 辅助设置 以安装插件. 添加数据 超级技能 至您的 AI 工具,使用以下命令:

npx skills add capawesome-team/skills --skill capacitor-plugins

然后使用下列提示:

Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capacitor-firebase/authentication` plugin in my project.

如果你喜欢 手动设置,通过运行以下命令来安装插件,并遵循下面的平台特定指令:

npm install @capacitor-firebase/authentication firebase
npx cap sync

如果您还没有将 Firebase 添加到您的项目中(机器人 编号 : iOS系统 编号 : 网页) (中文(简体) ).

打开 iOS系统,验证此功能是否包含在您的应用程序中 AppDelegate.swift数字 :

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
  return ApplicationDelegateProxy.shared.application(app, open: url, options: options)
}

请注意: 如果您在其中使用此插件 iOS系统 结合 @capacitor-firebase/messaging,然后在应用程序中添加以下内容: AppDelegate.swift数字 :

+ import FirebaseAuth

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
+    if Auth.auth().canHandle(url) {
+      return true
+    }
    return ApplicationDelegateProxy.shared.application(app, open: url, options: options)
}

进一步的安装步骤取决于选定的认证方法:

请注意:请注意,这个插件使用第三方SDK来提供本地登录. 这些SDK可以自行初始化并收集各种数据. 更多信息见 第三方 SDKs。 。 。 .

iOS系统

Swift 软件包管理器

在您的 capacitor.config.json (或 capacitor.config.ts) 避免 SwiftPM 软件包识别相撞数字 :

{
  "experimental": {
    "ios": {
      "spm": {
        "packageOptions": {
          "@capacitor-firebase/authentication": {
            "symlink": true
          }
        }
      }
    }
  }
}

请注意目标 packageOptions 支持需要控制器 CLI 8.4.0+ (中文(简体) )。 。 。 .

软件包特性

GoogleSignIn 和 Facebook SDK 是可选的,默认通过 Google 财务报告和审定财务报表 Facebook 软件包特性。 如果您不使用这些提供者, 请禁用相应的特性, 以使 SDK 不连接到您的应用程序中 :

{
  "experimental": {
    "ios": {
      "spm": {
        "swiftToolsVersion": "6.1",
        "packageTraits": {
          "@capacitor-firebase/authentication": ["Google"]
        }
      }
    }
  }
}

列出特征会明确替换默认,所以只启用您列出的特征. 以上例子保留了GoogleSignIn并排除了Facebook SDK. 使用 Lite 将两种情况排除在外:

{
  "experimental": {
    "ios": {
      "spm": {
        "swiftToolsVersion": "6.1",
        "packageTraits": {
          "@capacitor-firebase/authentication": ["Lite"]
        }
      }
    }
  }
}

这些特征是相当于 CapacitorFirebaseAuthentication/Google, (中文(简体) ), CapacitorFirebaseAuthentication/Facebook 财务报告和审定财务报表 CapacitorFirebaseAuthentication/Lite 可可宝地亚种. 调用 SDK 被排除的供应商的登录方法 .

请注意: SPM 特性支持需要Capacitor CLI 8.3.0+ (中文(简体) ) 和 X 代码 16.3+ (简体中文) (Swift 6.1+) (英语).

配置

这些配置值是可用的 :

Prop类型说明默认自兹
authDomainstring配置您要使用的自定义认证域 。 仅供Android和iOS使用.7.3.0 (单位:千美元)
skipNativeAuthboolean配置插件是否跳过本地认证 。 只有在您想要使用 Firebase JavaScript SDK 时才需要. 此配置选项对 Firebase 账户链接没有影响 . 注意插件可能在各个平台上表现不同. 仅供Android和iOS使用.false0.1.0 (中文(简体) )
providersstring[]配置由插件加载的供应商 。 可能的数值 : ["apple.com", "facebook.com", "gc.apple.com", "github.com", "google.com", "microsoft.com", "playgames.google.com", "twitter.com", "yahoo.com", "phone"] 仅供Android和iOS使用.[]0.1.0 (中文(简体) )

实例

单位 capacitor.config.json数字 :

{
  "plugins": {
    "FirebaseAuthentication": {
      "authDomain": undefined,
      "skipNativeAuth": false,
      "providers": ["apple.com", "facebook.com"]
    }
  }
}

单位 capacitor.config.ts数字 :

/// <reference types="@capacitor-firebase/authentication" />

import { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
  plugins: {
    FirebaseAuthentication: {
      authDomain: undefined,
      skipNativeAuth: false,
      providers: ["apple.com", "facebook.com"],
    },
  },
};

export default config;

火基地 JavaScript SDK

给 您可以找到如何使用 Firebase JS SDK 插件的信息.

演示

这里有一个实例: robingenz/电容器 -- -- 消防基地 -- -- 校正 -- -- 演示

启动模板

以下启动模板可供使用:

使用量

以下例子显示如何用电子邮件和密码签名,社交供应商,电话号码,电子邮件链接,匿名,自定义的代号,以及如何管理当前用户,重置密码,验证和更新电子邮件地址,设置语言,签名,删除用户,并使用Firebase模拟器.

签名并用电子邮件和密码签名

创建一个有电子邮件和密码的新用户账户,并用这些证书签名用户:

import { FirebaseAuthentication } from '@capacitor-firebase/authentication';

const createUserWithEmailAndPassword = async () => {
  const result = await FirebaseAuthentication.createUserWithEmailAndPassword({
    email: '[email protected]',
    password: '1234',
  });
  return result.user;
};

const signInWithEmailAndPassword = async () => {
  const result = await FirebaseAuthentication.signInWithEmailAndPassword({
    email: '[email protected]',
    password: '1234',
  });
  return result.user;
};

跟社工签约

在用户中与苹果,谷歌,Facebook,GitHub,微软,Twitter或雅虎等供应商在本地签名. 每一个提供者都要求设置步骤 安装 节。 Game Center的签入仅在iOS上提供,而Play Games的签入仅在Android上提供:

import { FirebaseAuthentication } from '@capacitor-firebase/authentication';

const signInWithApple = async () => {
  const result = await FirebaseAuthentication.signInWithApple();
  return result.user;
};

const signInWithFacebook = async () => {
  const result = await FirebaseAuthentication.signInWithFacebook();
  return result.user;
};

const signInWithGameCenter = async () => {
  const result = await FirebaseAuthentication.signInWithGameCenter();
  return result.user;
};

const signInWithGithub = async () => {
  const result = await FirebaseAuthentication.signInWithGithub();
  return result.user;
};

const signInWithGoogle = async () => {
  const result = await FirebaseAuthentication.signInWithGoogle();
  return result.user;
};

const signInWithMicrosoft = async () => {
  const result = await FirebaseAuthentication.signInWithMicrosoft();
  return result.user;
};

const signInWithPlayGames = async () => {
  const result = await FirebaseAuthentication.signInWithPlayGames();
  return result.user;
};

const signInWithTwitter = async () => {
  const result = await FirebaseAuthentication.signInWithTwitter();
  return result.user;
};

const signInWithYahoo = async () => {
  const result = await FirebaseAuthentication.signInWithYahoo();
  return result.user;
};

用电话号码签名

启动电话号码登录流程,向用户发送短信码,并用 confirmVerificationCode(...)。仅在Android和iOS上提供:

import { FirebaseAuthentication } from '@capacitor-firebase/authentication';

const signInWithPhoneNumber = async () => {
  return new Promise(async resolve => {
    // Attach `phoneCodeSent` listener to be notified as soon as the SMS is sent
    await FirebaseAuthentication.addListener('phoneCodeSent', async event => {
      // Ask the user for the SMS code
      const verificationCode = window.prompt(
        'Please enter the verification code that was sent to your mobile device.',
      );
      // Confirm the verification code
      const result = await FirebaseAuthentication.confirmVerificationCode({
        verificationId: event.verificationId,
        verificationCode,
      });
      resolve(result.user);
    });
    // Attach `phoneVerificationCompleted` listener to be notified if phone verification could be finished automatically
    await FirebaseAuthentication.addListener(
      'phoneVerificationCompleted',
      async event => {
        resolve(event.result.user);
      },
    );
    // Start sign in with phone number and send the SMS
    await FirebaseAuthentication.signInWithPhoneNumber({
      phoneNumber: '123456789',
    });
  });
};

向用户的电子邮件地址发送无密码的登录链接, 并在链接打开后完成登录 :

import { FirebaseAuthentication } from '@capacitor-firebase/authentication';

const sendSignInLinkToEmail = async () => {
  const email = '[email protected]';
  await FirebaseAuthentication.sendSignInLinkToEmail({
    email,
    actionCodeSettings: {
      // URL you want to redirect back to. The domain (www.example.com) for this
      // URL must be in the authorized domains list in the Firebase Console.
      url: 'https://www.example.com/finishSignUp?cartId=1234',
      // This must be true.
      handleCodeInApp: true,
      iOS: {
        bundleId: 'com.example.ios',
      },
      android: {
        packageName: 'com.example.android',
        installApp: true,
        minimumVersion: '12',
      },
      dynamicLinkDomain: 'example.page.link',
    },
  });
  // The link was successfully sent. Inform the user.
  // Save the email locally so you don't need to ask the user for it again
  // if they open the link on the same device.
  window.localStorage.setItem('emailForSignIn', email);
};

const signInWithEmailLink = async () => {
  // Get the email if available. This should be available if the user completes
  // the flow on the same device where they started it.
  const emailLink = window.location.href;
  // Confirm the link is a sign-in with email link.
  const { isSignInWithEmailLink } =
    await FirebaseAuthentication.isSignInWithEmailLink({
      emailLink,
    });
  if (!isSignInWithEmailLink) {
    return;
  }
  let email = window.localStorage.getItem('emailForSignIn');
  if (!email) {
    // User opened the link on a different device. To prevent session fixation
    // attacks, ask the user to provide the associated email again.
    email = window.prompt('Please provide your email for confirmation.');
  }
  // The client SDK will parse the code from the link for you.
  const result = await FirebaseAuthentication.signInWithEmailLink({
    email,
    emailLink,
  });
  // Clear email from storage.
  window.localStorage.removeItem('emailForSignIn');
  return result.user;
};

匿名签名

在用户中匿名签名, 例如让用户在创建账户前尝试您的应用程序 :

import { FirebaseAuthentication } from '@capacitor-firebase/authentication';

const signInAnonymously = async () => {
  const result = await FirebaseAuthentication.signInAnonymously();
  return result.user;
};

用自定义的符号或 OpenID 连接签名

用自定义的符号验证您自己的后端, 或使用任何 OpenID 连接提供者 :

import { FirebaseAuthentication } from '@capacitor-firebase/authentication';

const signInWithCustomToken = async () => {
  const result = await FirebaseAuthentication.signInWithCustomToken({
    token: '1234',
  });
  return result.user;
};

const signInWithOpenIdConnect = async () => {
  const result = await FirebaseAuthentication.signInWithOpenIdConnect({
    providerId: 'oidc.example.com',
  });
  return result.user;
};

获取当前用户和标识符

获取当前已签名的用户,他们的ID令牌,或者等待认证操作的结果. 这个 getPendingAuthResult() 方法只在Android上可用:

import { FirebaseAuthentication } from '@capacitor-firebase/authentication';

const getCurrentUser = async () => {
  const result = await FirebaseAuthentication.getCurrentUser();
  return result.user;
};

const getIdToken = async () => {
  const currentUser = await getCurrentUser();
  if (!currentUser) {
    return;
  }
  const result = await FirebaseAuthentication.getIdToken();
  return result.token;
};

const getPendingAuthResult = async () => {
  const result = await FirebaseAuthentication.getPendingAuthResult();
  return result.user;
};

发送和确认密码重置

向用户发送密码重置电子邮件,并用收到的出带码确认密码重置:

import { FirebaseAuthentication } from '@capacitor-firebase/authentication';

const sendPasswordResetEmail = async () => {
  await FirebaseAuthentication.sendPasswordResetEmail({
    email: '[email protected]',
  });
};

const confirmPasswordReset = async () => {
  await FirebaseAuthentication.confirmPasswordReset({
    oobCode: '1234',
    newPassword: '4321',
  });
};

校验用户的电子邮件地址

向当前登录的用户发送一个验证邮件, 并应用收到的带外代码 :

import { FirebaseAuthentication } from '@capacitor-firebase/authentication';

const sendEmailVerification = async () => {
  const currentUser = await getCurrentUser();
  if (!currentUser) {
    return;
  }
  await FirebaseAuthentication.sendEmailVerification();
};

const applyActionCode = async () => {
  await FirebaseAuthentication.applyActionCode({ oobCode: '1234' });
};

更新用户的电子邮件或密码

更新当前登录用户的电子邮件地址或密码 。 与 verifyBeforeUpdateEmail(...),新的电子邮件地址在更新前会核实:

import { FirebaseAuthentication } from '@capacitor-firebase/authentication';

const updateEmail = async () => {
  const currentUser = await getCurrentUser();
  if (!currentUser) {
    return;
  }
  await FirebaseAuthentication.updateEmail({
    newEmail: '[email protected]',
  });
};

const verifyBeforeUpdateEmail = async () => {
  const currentUser = await getCurrentUser();
  if (!currentUser) {
    return;
  }
  await FirebaseAuthentication.verifyBeforeUpdateEmail({
    newEmail: '[email protected]',
    actionCodeSettings: {
      url: 'https://www.example.com/[email protected]&cartId=123',
      iOS: {
        bundleId: 'com.example.ios'
      },
      android: {
        packageName: 'com.example.android',
        installApp: true,
        minimumVersion: '12'
      },
      handleCodeInApp: true
    }
  });
};

const updatePassword = async () => {
  const currentUser = await getCurrentUser();
  if (!currentUser) {
    return;
  }
  await FirebaseAuthentication.updatePassword({
    newPassword: '4321',
  });
};

查找电子邮件的登录方法

获取电子邮件地址可用的登录方法 :

import { FirebaseAuthentication } from '@capacitor-firebase/authentication';

const fetchSignInMethodsForEmail = async () => {
  const result = await FirebaseAuthentication.fetchSignInMethodsForEmail({
    email: '[email protected]',
  });
  return result.signInMethods;
};

设置语言

设定要使用的语言代码, 或者应用当前应用语言 :

import { FirebaseAuthentication } from '@capacitor-firebase/authentication';

const setLanguageCode = async () => {
  await FirebaseAuthentication.setLanguageCode({ languageCode: 'en-US' });
};

const useAppLanguage = async () => {
  await FirebaseAuthentication.useAppLanguage();
};

签名并删除用户

签名当前用户或永久删除用户账户 :

import { FirebaseAuthentication } from '@capacitor-firebase/authentication';

const signOut = async () => {
  await FirebaseAuthentication.signOut();
};

const deleteUser = async () => {
  await FirebaseAuthentication.deleteUser();
};

使用火地模拟器

将插件连接到本地端 火地模拟器 开发过程中的实例:

import { FirebaseAuthentication } from '@capacitor-firebase/authentication';

const useEmulator = async () => {
  await FirebaseAuthentication.useEmulator({
    host: '10.0.2.2',
    port: 9099,
  });
};

API 密码

应用动作代码(...)

applyActionCode(options: ApplyActionCodeOptions) => Promise<void>

应用通过电子邮件发送给用户的校验码 .

参数类型
optionsApplyActionCodeOptions

自: 0.2.2 (中文(简体) )


确认 Password 重置(...)

confirmPasswordReset(options: ConfirmPasswordResetOptions) => Promise<void>

完成密码重置进程.

参数类型
optionsConfirmPasswordResetOptions

自: 0.2.2 (中文(简体) )


确认验证码(...)

confirmVerificationCode(options: ConfirmVerificationCodeOptions) => Promise<SignInResult>

完成电话号码验证程序.

参数类型
optionsConfirmVerificationCodeOptions

回返情况: Promise<SignInResult>

自: 5.0.0 (单位:千美元)


创建 UserWith EmailAndPassword (.)

createUserWithEmailAndPassword(options: CreateUserWithEmailAndPasswordOptions) => Promise<SignInResult>

创建一个有电子邮件和密码的新用户账户. 如果创建了新账户,用户会自动签名.

参数类型
optionsCreateUserWithEmailAndPasswordOptions

回返情况: Promise<SignInResult>

自: 0.2.2 (中文(简体) )


删除用户( )

deleteUser() => Promise<void>

删除并签名出用户.

自: 1.3.0 (单位:千美元)


获取 SignInMethods ForEmail (...)

fetchSignInMethodsForEmail(options: FetchSignInMethodsForEmailOptions) => Promise<FetchSignInMethodsForEmailResult>

获取电子邮件地址的登录方法.

参数类型
optionsFetchSignInMethodsForEmailOptions

回返情况: Promise<FetchSignInMethodsForEmailResult>

自: 6.0.0 (单位:千美元)


获取当前用户( C)

getCurrentUser() => Promise<GetCurrentUserResult>

获取当前已签名的用户.

回返情况: Promise<GetCurrentUserResult>

自: 0.1.0 (中文(简体) )


获得PendingAuthResult ()

getPendingAuthResult() => Promise<SignInResult>

返回 SignInResult 如果您的应用程序启用了网络登录流, 而操作系统则在背景中清理应用程序 .

仅供Android使用.

回返情况: Promise<SignInResult>

自: 6.0.0 (单位:千美元)


获取 IdToken (...)

getIdToken(options?: GetIdTokenOptions | undefined) => Promise<GetIdTokenResult>

为当前登录的用户获取 Firebase Auth ID Token .

参数类型
optionsGetIdTokenOptions

回返情况: Promise<GetIdTokenResult>

自: 0.1.0 (中文(简体) )


获取 IdToken Result (...)

getIdTokenResult(options?: GetIdTokenResultOptions | undefined) => Promise<GetIdTokenResultResult>

返回用于识别用户身份的已解编的JSON Web Token(JWT)到Firebase服务.

参数类型
optionsGetIdTokenResultOptions

回返情况: Promise<GetIdTokenResultResult>

自: 7.4.0 (单位:千美元)


获取直接结果( C)

getRedirectResult() => Promise<SignInResult>

返回 SignInResult 从基于方向的登录流.

如果登录失败, 则出现出错 . 如果没有调试方向操作, 请返回 a SignInResult 与无效用户.

仅供Web使用.

回返情况: Promise<SignInResult>

自: 1.3.0 (单位:千美元)


获取 TenantId ()

getTenantId() => Promise<GetTenantIdResult>

拿房客身份证来.

回返情况: Promise<GetTenantIdResult>

自: 1.1.0 国家


isSignInWithEmailLink(options: IsSignInWithEmailLinkOptions) => Promise<IsSignInWithEmailLinkResult>

检查一个进入的链接是否是带有适合的电子邮件链接的登录 signInWithEmailLink。 。 。 .

参数类型
optionsIsSignInWithEmailLinkOptions

回返情况: Promise<IsSignInWithEmailLinkResult>

自: 1.1.0 国家


链接与 Apple (...)

linkWithApple(options?: SignInWithOAuthOptions | undefined) => Promise<LinkResult>

将用户账户与苹果认证提供者链接.

用户必须在原地层登录. 这个 skipNativeAuth 配置选项在此没有效果 .

参数类型
optionsSignInWithOAuthOptions

回返情况: Promise<SignInResult>

自: 1.1.0 国家


链接与电子邮件AndPassword (...)

linkWithEmailAndPassword(options: LinkWithEmailAndPasswordOptions) => Promise<LinkResult>

将用户账户与电子邮件认证提供者链接.

用户必须在原地层登录. 这个 skipNativeAuth 配置选项在此没有效果 .

参数类型
optionsLinkWithEmailAndPasswordOptions

回返情况: Promise<SignInResult>

自: 1.1.0 国家


linkWithEmailLink(options: LinkWithEmailLinkOptions) => Promise<LinkResult>

将用户账户与电子邮件认证提供者链接.

用户必须在原地层登录. 这个 skipNativeAuth 配置选项在此没有效果 .

参数类型
optionsLinkWithEmailLinkOptions

回返情况: Promise<SignInResult>

自: 1.1.0 国家


链接到脸书(...)

linkWithFacebook(options?: SignInWithOAuthOptions | undefined) => Promise<LinkResult>

链接用户账户与 Facebook 认证提供者 .

用户必须在原地层登录. 这个 skipNativeAuth 配置选项在此没有效果 .

参数类型
optionsSignInWithOAuthOptions

回返情况: Promise<SignInResult>

自: 1.1.0 国家


链接到 GameCenter (...)

linkWithGameCenter(options?: SignInWithOAuthOptions | undefined) => Promise<LinkResult>

将用户账户链接到游戏中心认证提供者.

用户必须在原地层登录. 这个 skipNativeAuth 配置选项在此没有效果 .

仅供iOS使用.

参数类型
optionsSignInWithOAuthOptions

回返情况: Promise<SignInResult>

自: 1.3.0 (单位:千美元)


链接到 Github (...)

linkWithGithub(options?: SignInWithOAuthOptions | undefined) => Promise<LinkResult>

将用户账户链接到 GitHub 认证提供者 .

用户必须在原地层登录. 这个 skipNativeAuth 配置选项在此没有效果 .

参数类型
optionsSignInWithOAuthOptions

回返情况: Promise<SignInResult>

自: 1.1.0 国家


链接到 Google (...)

linkWithGoogle(options?: SignInWithOAuthOptions | undefined) => Promise<LinkResult>

将用户账户与Google认证提供者链接.

用户必须在原地层登录. 这个 skipNativeAuth 配置选项在此没有效果 .

参数类型
optionsSignInWithOAuthOptions

回返情况: Promise<SignInResult>

自: 1.1.0 国家


链接微软(...)

linkWithMicrosoft(options?: SignInWithOAuthOptions | undefined) => Promise<LinkResult>

将用户账户与微软认证提供者链接.

用户必须在原地层登录. 这个 skipNativeAuth 配置选项在此没有效果 .

参数类型
optionsSignInWithOAuthOptions

回返情况: Promise<SignInResult>

自: 1.1.0 国家


链接与 OpenIdConnect (...)

linkWithOpenIdConnect(options: LinkWithOpenIdConnectOptions) => Promise<LinkResult>

用 OpenID 连接提供者链接用户账户.

参数类型
optionsSignInWithOpenIdConnectOptions

回返情况: Promise<SignInResult>

自: 6.1.0 (中文(简体) )


链接与 Phone 数字(...)

linkWithPhoneNumber(options: LinkWithPhoneNumberOptions) => Promise<void>

连接用户账户与电话号码认证提供者.

用户必须在原地层登录. 这个 skipNativeAuth 配置选项在此没有效果 .

使用 phoneVerificationCompleted 核查结束后通知听众. 使用 phoneVerificationFailed 当验证失败时, 要通知的听众 . 使用 phoneCodeSent 监听者获取验证码.

参数类型
optionsSignInWithPhoneNumberOptions

自: 1.1.0 国家


链接与 PlayGames (...)

linkWithPlayGames(options?: SignInWithOAuthOptions | undefined) => Promise<LinkResult>

链接用户账户与 PlayGames 认证提供者.

用户必须在原地层登录. 这个 skipNativeAuth 配置选项在此没有效果 .

仅供Android使用.

参数类型
optionsSignInWithOAuthOptions

回返情况: Promise<SignInResult>

自: 1.1.0 国家


链接到 Twitter (...)

linkWithTwitter(options?: SignInWithOAuthOptions | undefined) => Promise<LinkResult>

链接用户账户与Twitter认证提供者.

用户必须在原地层登录. 这个 skipNativeAuth 配置选项在此没有效果 .

参数类型
optionsSignInWithOAuthOptions

回返情况: Promise<SignInResult>

自: 1.1.0 国家


链接与 Yahoo (...)

linkWithYahoo(options?: SignInWithOAuthOptions | undefined) => Promise<LinkResult>

链接用户账户与 Yahoo 认证提供者.

用户必须在原地层登录. 这个 skipNativeAuth 配置选项在此没有效果 .

参数类型
optionsSignInWithOAuthOptions

回返情况: Promise<SignInResult>

自: 1.1.0 国家


重新装入( c)

reload() => Promise<void>

重新装入用户账户数据, 如果签名的话 .

自: 1.3.0 (单位:千美元)


撤销 AccessToken (...)

revokeAccessToken(options: RevokeAccessTokenOptions) => Promise<void>

撤销给定的访问符 。 目前只支持Apple OAuth访问符.

参数类型
optionsRevokeAccessTokenOptions

自: 6.1.0 (中文(简体) )


发送电子邮件验证(...)

sendEmailVerification(options?: SendEmailVerificationOptions | undefined) => Promise<void>

向当前在用户中签名的用户发送验证邮件 .

参数类型
optionsSendEmailVerificationOptions

自: 0.2.2 (中文(简体) )


发送 Password 重置邮件(...)

sendPasswordResetEmail(options: SendPasswordResetEmailOptions) => Promise<void>

发送密码重置邮件 .

参数类型
optionsSendPasswordResetEmailOptions

自: 0.2.2 (中文(简体) )


发送SignInLink To电子邮件(...)

sendSignInLinkToEmail(options: SendSignInLinkToEmailOptions) => Promise<void>

用指定的电子邮件向用户发送签名电子邮件链接 .

要完成电子邮件链接的签名, 请打电话 signInWithEmailLink 的电子邮件地址和电子邮件链接.

参数类型
optionsSendSignInLinkToEmailOptions

自: 1.1.0 国家


语言代码(...)

setLanguageCode(options: SetLanguageCodeOptions) => Promise<void>

设置用于认证操作的用户界面语言代码.

参数类型
optionsSetLanguageCodeOptions

自: 0.1.0 (中文(简体) )


设置持续(...)

setPersistence(options: SetPersistenceOptions) => Promise<void>

设置当前保存的认证会话的持久性类型 .

仅供Web使用.

参数类型
optionsSetPersistenceOptions

自: 5.2.0 (中文(简体) )


设置 TenantId (...)

setTenantId(options: SetTenantIdOptions) => Promise<void>

确定租户身份.

参数类型
optionsSetTenantIdOptions

自: 1.1.0 国家


匿名签名 ()

signInAnonymously() => Promise<SignInResult>

作为匿名用户签名.

回返情况: Promise<SignInResult>

自: 1.1.0 国家


签名InWithApple (...)

signInWithApple(options?: SignInWithOAuthOptions | undefined) => Promise<SignInResult>

启动 Apple 登录流量 .

参数类型
optionsSignInWithOAuthOptions

回返情况: Promise<SignInResult>

自: 0.1.0 (中文(简体) )


签名 InWithCustom Token (...)

signInWithCustomToken(options: SignInWithCustomTokenOptions) => Promise<SignInResult>

启动自定义托肯签名流程.

这种方法不能与 skipNativeAuth (原始内容存档于2019-10-12). Android and iOS. 在这种情况下,你必须使用 signInWithCustomToken 直接使用 Firebase JS SDK 接口.

参数类型
optionsSignInWithCustomTokenOptions

回返情况: Promise<SignInResult>

自: 0.1.0 (中文(简体) )


在电子邮件中签名 AndPassword (...)

signInWithEmailAndPassword(options: SignInWithEmailAndPasswordOptions) => Promise<SignInResult>

使用电子邮件和密码启动登录流程.

参数类型
optionsSignInWithEmailAndPasswordOptions

回返情况: Promise<SignInResult>

自: 0.2.2 (中文(简体) )


signInWithEmailLink(options: SignInWithEmailLinkOptions) => Promise<SignInResult>

使用电子邮件和签名电子邮件链接签名 .

参数类型
optionsSignInWithEmailLinkOptions

回返情况: Promise<SignInResult>

自: 1.1.0 国家


使用脸书签名(...)

signInWithFacebook(options?: SignInWithFacebookOptions | undefined) => Promise<SignInResult>

启动脸书登录流程 .

参数类型
optionsSignInWithFacebookOptions

回返情况: Promise<SignInResult>

自: 0.1.0 (中文(简体) )


签入 Game 中心(...)

signInWithGameCenter(options?: SignInWithOAuthOptions | SignInOptions | undefined) => Promise<SignInResult>

启动游戏中心的登录流程.

仅供iOS使用.

参数类型
optionsSignInWithOAuthOptions | SignInOptions

回返情况: Promise<SignInResult>

自: 1.3.0 (单位:千美元)


签名 InWithub (...)

signInWithGithub(options?: SignInWithOAuthOptions | undefined) => Promise<SignInResult>

启动 GitHub 登录流量 .

参数类型
optionsSignInWithOAuthOptions

回返情况: Promise<SignInResult>

自: 0.1.0 (中文(简体) )


使用 Google 签名(...)

signInWithGoogle(options?: SignInWithGoogleOptions | undefined) => Promise<SignInResult>

启动Google登录流量.

参数类型
optionsSignInWithGoogleOptions

回返情况: Promise<SignInResult>

自: 0.1.0 (中文(简体) )


签名InWith Microsoft (...)

signInWithMicrosoft(options?: SignInWithOAuthOptions | undefined) => Promise<SignInResult>

启动微软的登录流.

参数类型
optionsSignInWithOAuthOptions

回返情况: Promise<SignInResult>

自: 0.1.0 (中文(简体) )


在 OpenIdConnect 中签名(...)

signInWithOpenIdConnect(options: SignInWithOpenIdConnectOptions) => Promise<SignInResult>

启动 OpenID 连接签名流.

参数类型
optionsSignInWithOpenIdConnectOptions

回返情况: Promise<SignInResult>

自: 6.1.0 (中文(简体) )


签名 InWithPhone 数字(...)

signInWithPhoneNumber(options: SignInWithPhoneNumberOptions) => Promise<void>

使用电话号码启动登录流.

使用 phoneVerificationCompleted 核查结束后通知听众. 使用 phoneVerificationFailed 当验证失败时, 要通知的听众 . 使用 phoneCodeSent 监听者获取验证码.

仅供Android和iOS使用.

参数类型
optionsSignInWithPhoneNumberOptions

自: 0.1.0 (中文(简体) )


签入 PlayGames (...)

signInWithPlayGames(options?: SignInWithOAuthOptions | undefined) => Promise<SignInResult>

启动游戏游戏的登录流程.

仅供Android使用.

参数类型
optionsSignInWithOAuthOptions

回返情况: Promise<SignInResult>

自: 0.1.0 (中文(简体) )


签名 With Twitter (...)

signInWithTwitter(options?: SignInWithOAuthOptions | undefined) => Promise<SignInResult>

启动推特登录流量.

参数类型
optionsSignInWithOAuthOptions

回返情况: Promise<SignInResult>

自: 0.1.0 (中文(简体) )


签入 Yahoo (...)

signInWithYahoo(options?: SignInWithOAuthOptions | undefined) => Promise<SignInResult>

启动"雅虎"的签入流.

参数类型
optionsSignInWithOAuthOptions

回返情况: Promise<SignInResult>

自: 0.1.0 (中文(简体) )


符号输出( C)

signOut() => Promise<void>

启动出牌流.

自: 0.1.0 (中文(简体) )


unlink(options: UnlinkOptions) => Promise<UnlinkResult>

从用户账户中取消一个提供者的链接.

参数类型
optionsUnlinkOptions

回返情况: Promise<UnlinkResult>

自: 1.1.0 国家


更新电子邮件(...)

updateEmail(options: UpdateEmailOptions) => Promise<void>

更新当前用户签名的电子邮件地址.

参数类型
optionsUpdateEmailOptions

自: 0.1.0 (中文(简体) )


更新 Password (.)

updatePassword(options: UpdatePasswordOptions) => Promise<void>

更新当前用户签名的密码.

参数类型
optionsUpdatePasswordOptions

自: 0.1.0 (中文(简体) )


更新Profile (...)

updateProfile(options: UpdateProfileOptions) => Promise<void>

更新用户的配置数据.

参数类型
optionsUpdateProfileOptions

自: 1.3.0 (单位:千美元)


使用 AppLangage () 语言

useAppLanguage() => Promise<void>

设定用户界面语言代码为默认的app语言.

自: 0.1.0 (中文(简体) )


使用计算器(...)

useEmulator(options: UseEmulatorOptions) => Promise<void>

您的应用程序可以和认证模拟器交谈 .

参数类型
optionsUseEmulatorOptions

自: 0.2.0 (中文(简体) )


校验更新前的电子邮件(...)

verifyBeforeUpdateEmail(options: VerifyBeforeUpdateEmailOptions) => Promise<void>

在更新当前用户签名的电子邮件地址之前验证新的电子邮件地址 .

参数类型
optionsVerifyBeforeUpdateEmailOptions

自: 6.3.0 (单位:千美元)


追踪透明性

checkAppTrackingTransparencyPermission() => Promise<CheckAppTrackingTransparencyPermissionResult>

检查应用程序跟踪透明度的现状.

仅在iOS上可用.

回返情况: Promise<CheckAppTrackingTransparencyPermissionResult>

自: 7.2.0 联合国


追踪透明性

requestAppTrackingTransparencyPermission() => Promise<RequestAppTrackingTransparencyPermissionResult>

打开系统对话框以授权应用跟踪透明度 .

请注意: 用户可能已禁用设备设置中的跟踪请求,参见 苹果的文档。 。 。 .

仅在iOS上可用.

回返情况: Promise<CheckAppTrackingTransparencyPermissionResult>

自: 7.2.0 联合国


添加倾听器( “ 自动状态变化 ” ,...)

addListener(eventName: 'authStateChange', listenerFunc: AuthStateChangeListener) => Promise<PluginListenerHandle>

聆听用户的登录状态变化 .

请注意: 此听器不会在 skipNativeAuth 已使用。 取而代之的是火地JavaScript SDK.

参数类型
eventName'authStateChange'
listenerFuncAuthStateChangeListener

回返情况: Promise<PluginListenerHandle>

自: 0.1.0 (中文(简体) )


添加倾听器( “ id TokenChange ” ,...)

addListener(eventName: 'idTokenChange', listenerFunc: IdTokenChangeListener) => Promise<PluginListenerHandle>

听当前登录用户的 ID 令牌更改 .

请注意: 此听器不会在 skipNativeAuth 已使用。 取而代之的是火地JavaScript SDK.

参数类型
eventName'idTokenChange'
listenerFuncIdTokenChangeListener

回返情况: Promise<PluginListenerHandle>

自: 6.3.0 (单位:千美元)


添加聆听器( “ 手机验证完成 ” ,...)

addListener(eventName: 'phoneVerificationCompleted', listenerFunc: PhoneVerificationCompletedListener) => Promise<PluginListenerHandle>

听电话检查完毕.

这个听众只在两种情况下开火:

  1. 即时核查: 在某些情况下,可以立即拨打电话号码 不需要发送或输入核查代码.
  2. 自动检索: 在一些设备上,Google Play服务可以自动 检测进入的核查短消息,并在不进行核查的情况下进行核查 用户动作.

仅供Android使用.

参数类型
eventName'phoneVerificationCompleted'
listenerFuncPhoneVerificationCompletedListener

回返情况: Promise<PluginListenerHandle>

自: 1.3.0 (单位:千美元)


添加倾听器( “ 电话验证失败 ” ,...)

addListener(eventName: 'phoneVerificationFailed', listenerFunc: PhoneVerificationFailedListener) => Promise<PluginListenerHandle>

听电话验证失败.

参数类型
eventName'phoneVerificationFailed'
listenerFuncPhoneVerificationFailedListener

回返情况: Promise<PluginListenerHandle>

自: 1.3.0 (单位:千美元)


添加倾听器( “ 手机代码Sent' ,...)

addListener(eventName: 'phoneCodeSent', listenerFunc: PhoneCodeSentListener) => Promise<PluginListenerHandle>

听电话验证码.

参数类型
eventName'phoneCodeSent'
listenerFuncPhoneCodeSentListener

回返情况: Promise<PluginListenerHandle>

自: 1.3.0 (单位:千美元)


删除所有收听器( )

removeAllListeners() => Promise<void>

删除此插件的所有听众 .

自: 0.1.0 (中文(简体) )


接口

应用动作代码选项

Prop类型说明自兹
oobCodestring发给用户的验证码 .0.2.2 (中文(简体) )

确认 Password 重置选项

Prop类型说明自兹
oobCodestring发给用户的验证码 .0.2.2 (中文(简体) )
newPasswordstring新密码.

版本与发布记录

@capacitor-firebase/authentication 共发布 98 个版本,首次发布于 2022/03/20;过去 12 个月发布了 15 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.6.0latest2026/10/319 天前
8.5.22026/09/171 个月前
8.5.12026/09/022 个月前
8.5.02026/08/312 个月前
8.4.02026/08/122 个月前
8.3.02026/06/045 个月前

其他发布通道:dev → 8.0.0-dev.a9a3525.1766035511。

关于 @capacitor-firebase/authentication 的常见问题

@capacitor-firebase/authentication 是什么?

在Android,iOS,和Web上用于Firebase认证的电容插件.

如何安装 @capacitor-firebase/authentication?

在项目目录运行 npm install @capacitor-firebase/authentication,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capacitor-firebase/authentication 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capacitor-firebase/authentication 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capacitor-firebase/authentication 可以商用吗?

@capacitor-firebase/authentication 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@capacitor-firebase/authentication 的下载量有多少?

根据 npm 官方下载统计,@capacitor-firebase/authentication 在 2026/10/09 – 2026/11/07 这 30 天内被下载 635,517 次,日均约 21,184 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capacitor-firebase/authentication 还在维护吗?

最新版本 8.6.0 发布于 2026/10/31(9 天前);至今共发布 98 个版本,其中过去 12 个月发布了 15 个;首次发布于 2022/03/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。