Skip to main content

RespondChallengeDTO

Package: @nauth-toolkit/core Type: DTO (Request)

Unified data transfer object for responding to all authentication challenges with conditional validation based on challenge type.

import { RespondChallengeDTO } from '@nauth-toolkit/nestjs';

Properties

PropertyTypeRequiredDescription
sessionstringYesChallenge session token. UUID v4 format. Trimmed and lowercased.
typeChallengeTypeYesChallenge type. Must be: VERIFY_EMAIL, VERIFY_PHONE, MFA_REQUIRED, FORCE_CHANGE_PASSWORD, MFA_SETUP_REQUIRED.
codestringConditionalVerification code. 4-10 alphanumeric characters. Required for VERIFY_EMAIL, VERIFY_PHONE (with code), MFA_REQUIRED (non-passkey).
phonestringConditionalPhone number. E.164 format. Required for VERIFY_PHONE (phone collection/update step). Max 20 characters. When provided, updates the user's phone number and sends verification SMS.
newPasswordstringConditionalNew password. 8-128 characters. Required for FORCE_CHANGE_PASSWORD. Not trimmed.
methodMFAMethodTypeConditionalMFA method. Must be: sms, email, totp, passkey, backup. Required for MFA_REQUIRED and MFA_SETUP_REQUIRED.
credentialRecord<string, unknown>ConditionalPasskey credential object. Required for MFA_REQUIRED when method is passkey.
deviceIdnumberNoOptional device ID for MFA_REQUIRED when method supports multiple devices (TOTP, Passkey).
setupDataRecord<string, unknown>ConditionalMFA setup data. Required for MFA_SETUP_REQUIRED. Method-specific structure.

Example

Email Verification:

{
"session": "a21b654c-2746-4168-acee-c175083a65cd",
"type": "VERIFY_EMAIL",
"code": "123456"
}

Phone Verification (Collection/Update):

{
"session": "a21b654c-2746-4168-acee-c175083a65cd",
"type": "VERIFY_PHONE",
"phone": "+14155551234"
}

Note: The phone field can be used to:

  • Collect a phone number when user has none (e.g., social signup)
  • Update an existing phone number if user entered wrong number during signup

After submitting phone, backend sends verification SMS and returns the same challenge for code verification.

Phone Verification (Code):

{
"session": "a21b654c-2746-4168-acee-c175083a65cd",
"type": "VERIFY_PHONE",
"code": "123456"
}

MFA Verification:

{
"session": "a21b654c-2746-4168-acee-c175083a65cd",
"type": "MFA_REQUIRED",
"method": "totp",
"code": "123456"
}

Password Change:

{
"session": "a21b654c-2746-4168-acee-c175083a65cd",
"type": "FORCE_CHANGE_PASSWORD",
"newPassword": "NewSecurePass123!"
}

Used By