|
1 | 1 | /* eslint-disable max-lines */ |
2 | 2 | import { appInsights } from '@logto/app-insights/node'; |
3 | | -import { InteractionEvent, VerificationType, type User } from '@logto/schemas'; |
| 3 | +import { InteractionEvent, MfaFactor, VerificationType, type User } from '@logto/schemas'; |
| 4 | +import { maskEmail, maskPhone } from '@logto/shared'; |
4 | 5 | import { conditional, trySafe } from '@silverhand/essentials'; |
5 | 6 |
|
6 | 7 | import RequestError from '#src/errors/RequestError/index.js'; |
@@ -339,11 +340,29 @@ export default class ExperienceInteraction { |
339 | 340 | const mfaValidator = new MfaValidator(mfaSettings, user); |
340 | 341 | const isVerified = mfaValidator.isMfaVerified(this.verificationRecordsArray); |
341 | 342 |
|
| 343 | + const { primaryEmail, primaryPhone } = user; |
| 344 | + // Build masked identifiers for UX hints when applicable |
| 345 | + const maskedIdentifiers: Record<string, string> = { |
| 346 | + ...(mfaValidator.availableUserMfaVerificationTypes.includes( |
| 347 | + MfaFactor.EmailVerificationCode |
| 348 | + ) && primaryEmail |
| 349 | + ? { [MfaFactor.EmailVerificationCode]: maskEmail(primaryEmail) } |
| 350 | + : {}), |
| 351 | + ...(mfaValidator.availableUserMfaVerificationTypes.includes( |
| 352 | + MfaFactor.PhoneVerificationCode |
| 353 | + ) && primaryPhone |
| 354 | + ? { [MfaFactor.PhoneVerificationCode]: maskPhone(primaryPhone) } |
| 355 | + : {}), |
| 356 | + }; |
| 357 | + |
342 | 358 | assertThat( |
343 | 359 | isVerified, |
344 | 360 | new RequestError( |
345 | 361 | { code: 'session.mfa.require_mfa_verification', status: 403 }, |
346 | | - { availableFactors: mfaValidator.availableUserMfaVerificationTypes } |
| 362 | + { |
| 363 | + availableFactors: mfaValidator.availableUserMfaVerificationTypes, |
| 364 | + maskedIdentifiers, |
| 365 | + } |
347 | 366 | ) |
348 | 367 | ); |
349 | 368 | } |
|
0 commit comments