MultiFactorUser interface

Giao diện xác định các thuộc tính và hoạt động liên quan đến nhiều yếu tố liên quan đến Người dùng .

Chữ ký:

export interface MultiFactorUser 

Của cải

Tài sản Kiểu Sự miêu tả
đã đăng kýYếu tố Thông tin đa yếu tố [] Trả về danh sách các yếu tố thứ hai đã đăng ký của người dùng.

phương pháp

Phương pháp Sự miêu tả
ghi danh(xác nhận, tên hiển thị) Đăng ký yếu tố thứ hai được xác định bởi MultiFactorAssertion cho người dùng.
getSession() Trả về mã định danh phiên cho hoạt động đăng ký yếu tố thứ hai. Điều này được sử dụng để xác định người dùng đang cố gắng đăng ký yếu tố thứ hai.
hủy đăng ký (tùy chọn) Hủy đăng ký yếu tố thứ hai được chỉ định.

MultiFactorUser.enrolledFactors

Trả về danh sách các yếu tố thứ hai đã đăng ký của người dùng.

Chữ ký:

readonly enrolledFactors: MultiFactorInfo[];

MultiFactorUser.enroll()

Đăng ký yếu tố thứ hai được xác định bởi MultiFactorAssertion cho người dùng.

Về độ phân giải, mã thông báo của người dùng được cập nhật để phản ánh sự thay đổi trong tải trọng JWT. Chấp nhận tham số tên hiển thị bổ sung được sử dụng để xác định yếu tố thứ hai cho người dùng cuối. Việc xác thực lại gần đây là cần thiết để hoạt động này thành công. Khi đăng ký thành công, các phiên Firebase hiện tại (mã thông báo làm mới) sẽ bị thu hồi. Khi một yếu tố mới được đăng ký, một thông báo qua email sẽ được gửi đến email của người dùng.

Chữ ký:

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

Thông số

Tham số Kiểu Sự miêu tả
quả quyết Khẳng định đa yếu tố Xác nhận đa yếu tố để đăng ký.
tên hiển thị chuỗi | vô giá trị Tên hiển thị của yếu tố thứ hai.

Trả về:

Hứa<void>

Ví dụ

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

Trả về mã định danh phiên cho hoạt động đăng ký yếu tố thứ hai. Điều này được sử dụng để xác định người dùng đang cố gắng đăng ký yếu tố thứ hai.

Chữ ký:

getSession(): Promise<MultiFactorSession>;

Trả về:

Lời hứa< Phiên đa yếu tố >

Lời hứa được giải quyết bằng MultiFactorSession .

Ví dụ

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

Hủy đăng ký yếu tố thứ hai được chỉ định.

Để chỉ định hệ số cần loại bỏ, hãy chuyển một đối tượng MultiFactorInfo (được lấy từ MultiFactorUser.enrolledFactors ) hoặc chuỗi UID của yếu tố. Phiên không bị thu hồi khi tài khoản được hủy đăng ký. Một thông báo qua email có thể sẽ được gửi đến người dùng để thông báo cho họ về sự thay đổi. Việc xác thực lại gần đây là cần thiết để hoạt động này thành công. Khi một yếu tố hiện có bị hủy đăng ký, một thông báo qua email sẽ được gửi đến email của người dùng.

Chữ ký:

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

Thông số

Tham số Kiểu Sự miêu tả
lựa chọn Thông tin đa yếu tố | sợi dây Tùy chọn đa yếu tố để hủy đăng ký.

Trả về:

Hứa<void>

  • Promise sẽ được giải quyết khi thao tác hủy đăng ký hoàn tất.

Ví dụ

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