You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular应用给Firebase添加MFA:手机号参数报错求助

Fix: "phoneNumber does not exist in type 'UpdateMultiFactorInfoRequest'" in Firebase Admin SDK MFA Update

This error pops up due to TypeScript's strict type checking—here's how to fix it:

Why the Error Happens

The enrolledFactors array expects items of type UpdateMultiFactorInfoRequest, a base type for all MFA factors. But phoneNumber is a property that only exists on the phone-specific subtype UpdatePhoneMultiFactorInfoRequest. Since TypeScript can't automatically infer you're targeting a phone-based MFA factor, it throws an error when you include phoneNumber in the object.

Note: The official documentation example is likely written in JavaScript (which doesn't enforce type checks), so it works there without extra steps.

Solutions

1. Use a Type Assertion

Explicitly tell TypeScript your object is a UpdatePhoneMultiFactorInfoRequest using the as keyword:

import * as admin from 'firebase-admin';

admin.auth().updateUser('123456789', {
  multiFactor: {
    enrolledFactors: [
      {
        phoneNumber: '+16505550003',
        displayName: 'Spouse\'s phone',
        factorId: 'phone',
      } as admin.auth.UpdatePhoneMultiFactorInfoRequest,
    ],
  },
})
.then((userRecord) => {
  console.log(userRecord.multiFactor.enrolledFactors);
})
.catch((error) => {
  console.log(error);
});

2. Explicitly Type the Factor Object

Define the phone MFA factor as a variable with the correct type first, then add it to the array:

import * as admin from 'firebase-admin';

// Define the phone factor with the specific type
const phoneMfaFactor: admin.auth.UpdatePhoneMultiFactorInfoRequest = {
  phoneNumber: '+16505550003',
  displayName: 'Spouse\'s phone',
  factorId: 'phone',
};

admin.auth().updateUser('123456789', {
  multiFactor: {
    enrolledFactors: [phoneMfaFactor],
  },
})
.then((userRecord) => {
  console.log(userRecord.multiFactor.enrolledFactors);
})
.catch((error) => {
  console.log(error);
});

Both methods resolve the type error by clarifying to TypeScript that you're working with a phone-based MFA factor, which includes the phoneNumber property.

内容的提问来源于stack exchange,提问作者GrzesiekO

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 10:17:59