跳过内容

开始使用

终端窗口
bun add @capgo/capacitor-firebase-authentication
bunx cap sync
import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';

Applies a verification code sent to the user by email.

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.applyActionCode({} as ApplyActionCodeOptions);

完成密码重置过程。

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

删除用户

删除用户并注销。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.deleteUser();

fetchSignInMethodsForEmail

获取用户电子邮件的登录方式

获取指定电子邮件地址的登录方法。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.fetchSignInMethodsForEmail({} as FetchSignInMethodsForEmailOptions);

获取当前已登录的用户。

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();

获取 Firebase Auth ID Token 的当前已登录用户。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.getIdToken();

返回一个用来标识用户到 Firebase 服务的 JSON Web 令牌 (JWT)。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.getIdTokenResult();

返回重定向式登录流中的 SignInResult 如果登录失败,则会以错误形式返回。如果没有调用重定向操作,则返回一个

用户为 null 的 SignInResult 仅适用于 Web。

复制到剪贴板

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.getRedirectResult();

获取租户 ID。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.getTenantId();

检查是否为电子邮件链接的登录链接,适合 signInWithEmailLink.

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.isSignInWithEmailLink({} as IsSignInWithEmailLinkOptions);

将用户帐户与 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);

将用户帐户与电子邮件身份验证提供商关联。

用户必须在原生层上登录。 skipNativeAuth 此配置选项在这里无效。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.linkWithEmailLink({} as LinkWithEmailLinkOptions);

将用户帐户与Facebook身份验证提供商关联。

用户必须在原生层上登录。 skipNativeAuth 此配置选项在这里无效。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.linkWithFacebook();

链接用户账户与Game Center认证提供者。

用户必须在原生层上登录。 该配置选项在此处无效。 仅适用于iOS。 skipNativeAuth 复制到剪贴板

标题:“linkWithGithub”

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.linkWithGameCenter();

Links the user account with GitHub authentication provider.

标题:“linkWithGithub” skipNativeAuth 链接用户账户与__CAPGO_KEEP_0__认证提供者。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.linkWithGithub();

linkWithGoogle

《linkWithGoogle》

与Google身份验证提供者绑定用户账户。

用户必须在原生层上登录。 该配置选项在此处无效。 skipNativeAuth 复制到剪贴板

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.linkWithGoogle();

用户必须在原生层上登录。 该配置选项在此处无效。

复制到剪贴板 skipNativeAuth 《linkWithOpenIdConnect》

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.linkWithMicrosoft();

复制到剪贴板

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.linkWithOpenIdConnect({} as LinkWithOpenIdConnectOptions);

linkWithPhoneNumber

标题:使用手机号码

使用手机号码验证提供者链接用户帐户。

用户必须在原生层上登录。 此配置选项在此处无效。 skipNativeAuth 使用此监听器来接收验证完成的通知。 使用此监听器来接收验证失败的通知。 使用此监听器来获取验证 ID。

复制到剪贴板 phoneVerificationCompleted 标题:使用Play Games phoneVerificationFailed 使用Play Games验证提供者链接用户帐户。 phoneCodeSent The user must be logged in on the native layer. The

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.linkWithPhoneNumber({} as LinkWithPhoneNumberOptions);

linkWithPlayGames

Use the

listener to be notified when the verification is completed. Use the

用户必须在原生层上登录。 skipNativeAuth 此配置选项在这里无效。

仅适用于 Android。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.linkWithPlayGames();

将用户帐户与 Twitter 身份验证提供者关联。

用户必须在原生层上登录。 skipNativeAuth 此配置选项在这里无效。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.linkWithTwitter();

将用户帐户与 Yahoo 身份验证提供者关联。

用户必须在原生层上登录。 skipNativeAuth 此配置选项在此处无效。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.linkWithYahoo();

重新加载已登录用户的帐户数据。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.reload();

撤销给定的访问令牌。目前仅支持 Apple OAuth 访问令牌。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.revokeAccessToken({} as RevokeAccessTokenOptions);

向当前已登录用户发送验证邮件。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.sendEmailVerification();

发送密码重置邮件。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.sendPasswordResetEmail({} as SendPasswordResetEmailOptions);

发送登录链接到指定电子邮件的用户。

使用电子邮件链接完成登录,请调用 signInWithEmailLink 使用电子邮件地址和电子邮件中提供的电子邮件链接。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.sendSignInLinkToEmail({} as SendSignInLinkToEmailOptions);

设置用于身份验证操作的用户界面语言code。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.setLanguageCode({} as SetLanguageCodeOptions);

设置当前保存的身份验证会话的持久性类型。

仅在 Web 中可用。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.setPersistence({} as SetPersistenceOptions);

设置租户 ID。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.setTenantId({} as SetTenantIdOptions);

signInAnonymously

标题:匿名登录

作为匿名用户登录。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInAnonymously();

启动 Apple 登录流程。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithApple();

启动自定义令牌登录流程。

此方法不能与 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);

复制到剪贴板

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithEmailAndPassword({} as SignInWithEmailAndPasswordOptions);

复制到剪贴板

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithEmailLink({} as SignInWithEmailLinkOptions);

signInWithFacebook

复制到剪贴板

启动 Facebook 登录流程。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithFacebook();

signInWithGameCenter

游戏中心登录部分

启动游戏中心登录流程。

仅适用于 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

使用手机号登录

使用

监听完成验证 phoneVerificationCompleted 监听验证失败 phoneVerificationFailed 获取验证 ID phoneCodeSent 复制到剪贴板

仅适用于 Android 和 iOS。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithPhoneNumber({} as SignInWithPhoneNumberOptions);

启动 Play Games 登录流程。

仅适用于 Android。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithPlayGames();

启动 Twitter 登录流程。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithTwitter();

启动 Yahoo 登录流程。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signInWithYahoo();

signOut

登出

开始登出流程。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.signOut();
解绑

解绑一个提供者从一个用户账户。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.unlink({} as UnlinkOptions);

更新当前登录用户的电子邮件地址。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.updateEmail({} as UpdateEmailOptions);

updatePassword

更新密码

更新当前登录用户的密码。

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.updatePassword({} as UpdatePasswordOptions);

updateProfile

更新用户资料

更新用户资料

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.updateProfile({} as UpdateProfileOptions);

Sets the user-facing language code to be the default app language.

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.useAppLanguage();

useEmulator

模拟器

模拟器

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.useEmulator({} as UseEmulatorOptions);

verifyBeforeUpdateEmail

验证新电子邮件地址

验证新电子邮件地址

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.verifyBeforeUpdateEmail({} as VerifyBeforeUpdateEmailOptions);

checkAppTrackingTransparencyPermission

检查App跟踪透明度权限

检查当前App跟踪透明度状态

仅在iOS上可用

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.checkAppTrackingTransparencyPermission();

requestAppTrackingTransparencyPermission

请求App跟踪透明度权限

打开系统对话框,授权App跟踪透明度

注意: 用户可能在设备设置中禁用了跟踪请求,见 苹果文档.

仅在iOS上可用

import { FirebaseAuthentication } from '@capgo/capacitor-firebase-authentication';
await FirebaseAuthentication.requestAppTrackingTransparencyPermission();

类型参考

类型参考

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

标题: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;
}
export interface GetIdTokenOptions {
/**
* Force refresh regardless of token expiration.
*
* @since 0.1.0
*/
forceRefresh: boolean;
}
export interface GetIdTokenResult {
/**
* The Firebase Auth ID token JWT string.
*
* @since 0.1.0
*/
token: string;
}

GetIdTokenResultOptions

标题:GetIdTokenResultOptions
export interface GetIdTokenResultOptions {
/**
* Force refresh regardless of token expiration.
*
* @since 7.4.0
*/
forceRefresh: boolean;
}

GetIdTokenResultResult

标题: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>;
}

本页面是从插件生成的。 src/definitions.ts当公共 API 上游发生变化时,请重新同步。