MultiFactorUser interface

定义与用户相关的多因素相关属性和操作的接口

签名:

export interface MultiFactorUser 

特性

财产类型描述
登记因素多因素信息[]返回用户注册的第二因素的列表。

方法

方法描述
注册(断言,显示名称)注册由用户的MultiFactorAssertion标识的第二个因素。
获取会话()返回第二因素注册操作的会话标识符。这用于识别尝试注册第二个因素的用户。
取消注册(选项)取消注册指定的第二个因素。

MultiFactorUser.enrolledFactors

返回用户注册的第二因素的列表。

签名:

readonly enrolledFactors: MultiFactorInfo[];

MultiFactorUser.enroll()

注册由用户的MultiFactorAssertion标识的第二个因素。

解析时,用户令牌将更新以反映 JWT 负载中的更改。接受用于向最终用户标识第二个因素的附加显示名称参数。此操作需要最近重新进行身份验证才能成功。成功注册后,现有 Firebase 会话(刷新令牌)将被撤销。注册新因素时,系统会向用户的电子邮件发送电子邮件通知。

签名:

enroll(assertion: MultiFactorAssertion, displayName?: string | null): Promise<void>;

参数

范围类型描述
断言多因素断言用于注册的多因素断言。
显示名称字符串 |无效的第二个因素的显示名称。

返回:

承诺<无效>

例子

const multiFactorUser = multiFactor(auth.currentUser);
const multiFactorSession = await multiFactorUser.getSession();

// Send verification code.
const phoneAuthProvider = new PhoneAuthProvider(auth);
const phoneInfoOptions = {
  phoneNumber: phoneNumber,
  session: multiFactorSession
};
const verificationId = await phoneAuthProvider.verifyPhoneNumber(phoneInfoOptions, appVerifier);

// Obtain verification code from user.
const phoneAuthCredential = PhoneAuthProvider.credential(verificationId, verificationCode);
const multiFactorAssertion = PhoneMultiFactorGenerator.assertion(phoneAuthCredential);
await multiFactorUser.enroll(multiFactorAssertion);
// Second factor enrolled.

MultiFactorUser.getSession()

返回第二因素注册操作的会话标识符。这用于识别尝试注册第二个因素的用户。

签名:

getSession(): Promise<MultiFactorSession>;

返回:

Promise< MultiFactorSession >

通过MultiFactorSession解决的承诺

例子

const multiFactorUser = multiFactor(auth.currentUser);
const multiFactorSession = await multiFactorUser.getSession();

// Send verification code.
const phoneAuthProvider = new PhoneAuthProvider(auth);
const phoneInfoOptions = {
  phoneNumber: phoneNumber,
  session: multiFactorSession
};
const verificationId = await phoneAuthProvider.verifyPhoneNumber(phoneInfoOptions, appVerifier);

// Obtain verification code from user.
const phoneAuthCredential = PhoneAuthProvider.credential(verificationId, verificationCode);
const multiFactorAssertion = PhoneMultiFactorGenerator.assertion(phoneAuthCredential);
await multiFactorUser.enroll(multiFactorAssertion);

MultiFactorUser.unenroll()

取消注册指定的第二个因素。

要指定要删除的因素,请传递MultiFactorInfo对象(从MultiFactorUser.enrolledFactors检索) ) 或因子的 UID 字符串。当帐户取消注册时,会话不会被撤销。可能会向用户发送电子邮件通知,通知他们更改。此操作需要最近重新进行身份验证才能成功。当取消注册现有因素时,系统会向用户的电子邮件发送电子邮件通知。

签名:

unenroll(option: MultiFactorInfo | string): Promise<void>;

参数

范围类型描述
选项多因素信息|细绳取消注册的多因素选项。

返回:

承诺<无效>

  • 当取消注册操作完成时解析的Promise

例子

const multiFactorUser = multiFactor(auth.currentUser);
// Present user the option to choose which factor to unenroll.
await multiFactorUser.unenroll(multiFactorUser.enrolledFactors[i])