Skip to main content

Data Transfer Objects (DTOs)

Package: @nauth-toolkit/core Type: Data Transfer Objects

Platform-agnostic request and response DTOs for authentication operations. All DTOs use class-validator decorators for automatic validation.

import { SignupDTO, LoginDTO, AuthResponseDTO } from '@nauth-toolkit/nestjs';

Overview

DTOs provide type-safe, validated data structures for all authentication operations. They ensure:

  • Type Safety - Full TypeScript support with IntelliSense
  • Automatic Validation - class-validator decorators enforce rules
  • Framework Integration - NestJS and Express handle validation automatically
note

All DTOs are automatically validated by framework adapters. No manual validation required.

Authentication DTOs

DTODescriptionDocumentation
AuthResponseDTOUnified authentication responseTokens OR challenge (MFA/verification)
LoginDTOUser login requestIdentifier (email/username/phone) and password
LogoutAllDTOLogout all sessionsRevoke all user sessions
LogoutAllResponseDTOLogout all responseCount of revoked sessions
LogoutDTOLogout requestSession termination
LogoutResponseDTOLogout responseSuccess confirmation
RefreshTokenDTOToken refresh requestRefresh token
SignupDTOUser registration requestEmail, password, optional username/phone
TrustDeviceResponseDTODevice trust responseDevice trust token
IsTrustedDeviceResponseDTOTrusted device check responseWhether current device is trusted

Session Management DTOs

DTODescriptionDocumentation
GetUserSessionsDTOGet user sessionsPagination and filters
GetUserSessionsResponseDTOSessions list responseActive sessions with details
LogoutSessionDTOLogout specific sessionSession ID
LogoutSessionResponseDTOSession logout responseSuccess confirmation

Admin Operations DTOs

DTODescriptionDocumentation
AdminSetPasswordDTOAdmin password resetSet user password by sub
AdminSignupDTOAdmin user creationCreate user with override capabilities (bypass verification, force password change)
AdminSignupSocialDTOAdmin social user importImport social users from external platforms (Cognito, Auth0) with social linkage
AdminSignupSocialResponseDTOAdmin social import responseUser object and social account confirmation
DeleteUserDTOAdmin user deletionHard delete user with complete cascade cleanup
DeleteUserResponseDTOAdmin deletion responseDeletion confirmation with cascade counts
DisableUserDTOAdmin account lockingPermanent account lock with session revocation
DisableUserResponseDTOAdmin lock responseLock confirmation with revoked session count
EnableUserDTOAdmin account unlockingClear lock fields and reset failed attempts
EnableUserResponseDTOAdmin unlock responseUnlock confirmation with updated user status
GetUsersDTOAdmin user listingPaginated user search with advanced filtering
GetUsersResponseDTOAdmin listing responseUser list with pagination metadata
AdminLogoutAllDTOAdmin global logoutRevoke all sessions for a target user
AdminUpdateUserAttributesDTOAdmin user updateUpdate user profile attributes with required sub
AdminResetPasswordDTOAdmin password reset requestInitiate admin-driven password reset
AdminRevokeSessionDTOAdmin session revokeRevoke a specific session for a target user
ConfirmAdminResetPasswordDTOConfirm admin password resetCode, new password, and session
UpdateVerifiedStatusRequestDTOAdmin verification statusUpdate email/phone verified flags

Password Management DTOs

DTODescriptionDocumentation
ChangePasswordDTOChange password requestCurrent and new password
ChangePasswordResponseDTOChange password responseSuccess confirmation
ConfirmForgotPasswordDTOConfirm password resetReset code and new password
ForgotPasswordDTOForgot password flowRequest reset code
ResetPasswordDTOReset password requestReset token and new password
SetMustChangePasswordDTOForce password changeAdmin operation
SetMustChangePasswordResponseDTOForce password change responseSuccess confirmation

Email Verification DTOs

DTODescriptionDocumentation
ResendVerificationEmailDTOResend verification emailUser sub or email
ResendVerificationEmailResponseDTOResend email responseToken ID
SendVerificationEmailDTOSend verification emailUser sub and optional base URL
SendVerificationEmailResponseDTOSend email responseToken ID
VerifyEmailResponseDTOVerify email responseSuccess message
VerifyEmailWithCodeDTOVerify email with codeEmail address and 6-digit verification code
VerifyEmailWithTokenDTOVerify email with tokenVerification token from URL

Phone Verification DTOs

DTODescriptionDocumentation
ResendVerificationSMSDTOResend verification SMSUser sub or phone
ResendVerificationSMSResponseDTOResend SMS responseToken ID
SendVerificationSMSDTOSend verification SMSUser sub
SendVerificationSMSResponseDTOSend SMS responseToken ID
VerifyPhoneResponseDTOVerify phone responseSuccess message
VerifyPhoneWithCodeBySubDTOVerify phone by subUser sub and code
VerifyPhoneWithCodeDTOVerify phone with codePhone number and code

Challenge Flow DTOs

DTODescriptionDocumentation
AuthChallengeDTOChallenge detailsChallenge type enum and parameters
ChallengeResponseDataChallenge response typesTypeScript discriminated union types
GetChallengeDataDTOGet challenge dataChallenge session token
GetChallengeDataResponseDTOChallenge data responseChallenge information
RespondChallengeDTORespond to challengeChallenge session and response data
AuthChallengeResponseDTOChallenge responseChallenge type, session, and parameters

MFA DTOs

DTODescriptionDocumentation
AdminGetMFAStatusDTOAdmin get MFA statusTarget user sub
AdminGetUserDevicesDTOAdmin get user MFA devicesTarget user sub
AdminRemoveDeviceDTOAdmin remove MFA device by IDDevice ID
AdminSetPreferredDeviceDTOAdmin set preferred MFA deviceUser sub and device ID
GetAvailableMethodsDTOGet available MFA methodsUser sub
GetMFAStatusResponseDTOMFA status responseStatus fields
GetSetupDataDTOGet MFA setup dataChallenge session and method
GetSetupDataResponseDTOSetup data responseProvider-specific setup data
GetUserDevicesDTOGet user MFA devices (self-service)User from context
RemoveDeviceDTORemove MFA device by IDDevice ID
SetMFAExemptionDTOSet MFA exemptionUser sub, exempt flag, reason
SetPreferredDeviceDTOSet preferred MFA deviceDevice ID
SetupMFADTOSetup MFA deviceMethod name, setup data
VerifyMFACodeDTOVerify MFA codeMethod, code

Social Authentication DTOs

DTODescriptionDocumentation
CanSetPasswordDTOCheck if password can be setUser sub
CanSetPasswordResponseDTOCan set password responseBoolean flag
GetLinkedAccountsDTOGet linked accountsUser sub
GetLinkedAccountsResponseDTOLinked accounts responseArray of linked providers
LinkSocialAccountDTOLink social accountProvider, code, state
LinkSocialAccountResponseDTOLink account responseSuccess confirmation
SetPasswordForSocialUserDTOSet password for social userUser sub and new password
SetPasswordForSocialUserResponseDTOSet password responseSuccess confirmation
SocialCallbackFormDTOOAuth callback form data (POST)Apple form_post callbacks
SocialCallbackQueryDTOOAuth callback query params (GET)Google, Facebook callbacks
SocialExchangeDTOExchange social redirect tokenOne-time exchange token
SocialRedirectCallbackResponseDTOCallback redirect responseurl for @Redirect()
StartSocialRedirectQueryDTOStart social redirect flowreturnTo, appState, action
StartSocialRedirectResponseDTOStart redirect responseurl for @Redirect()
UnlinkSocialAccountDTOUnlink social accountUser sub and provider
UnlinkSocialAccountResponseDTOUnlink account responseSuccess confirmation
VerifyTokenDTOVerify native social tokenProvider, ID token, access token
HandleCallbackDTOHandle OAuth callbackProvider callback data

User Management DTOs

DTODescriptionDocumentation
GetUserByEmailDTOGet user by emailEmail address
GetUserByIdDTOGet user by IDUser sub (UUID)
UpdateUserAttributesDTOUpdate user attributesUser attributes (self-service)
UserResponseDTOUser profile dataUser information (excludes sensitive fields)
UserUpdateDTOUser update requestUser profile fields

Audit & Client Info DTOs

DTODescriptionDocumentation
GetClientInfoDTOGet client informationNo parameters (from context)
GetDeviceTokenResponseDTODevice token responseDevice trust token
GetEventsByTypeDTOGet events by typeEvent type, pagination, date range
GetIpAddressResponseDTOIP address responseClient IP address
GetRiskAssessmentHistoryDTOGet risk assessment historyUser sub, limit
GetSessionIdResponseDTOSession ID responseJWT session ID
GetSuspiciousActivityDTOGet suspicious activityUser sub (optional), limit
GetUserAgentResponseDTOUser agent responseClient user agent
GetUserAuthHistoryDTOGet auth historyUser sub, pagination, filters
GetUserAuthHistoryResponseDTOAuth history responsePaginated event list
GetEventsByTypeResponseDTOEvents by type responseFiltered event list
GetRiskAssessmentHistoryResponseDTORisk assessment responseRisk scores and factors
GetSuspiciousActivityResponseDTOSuspicious activity responseFlagged events

Token Validation DTOs

DTODescriptionDocumentation
ValidateAccessTokenDTOValidate access tokenToken string
ValidateAccessTokenResponseDTOValidation responseDecoded JWT payload

Error & Utility DTOs

DTODescriptionDocumentation
ErrorResponseDTOStandardized error formatError code, message, details
HasProviderDTOCheck if provider existsProvider name
ListProvidersResponseDTOList providers responseArray of provider names
ResendCodeDTOResend verification codeChallenge session
ResendCodeResponseDTOResend code responseSuccess confirmation

Usage

All DTOs are automatically validated by framework adapters:

import { Controller, Post, Body } from '@nestjs/common';
import { AuthService, SignupDTO, AuthResponseDTO } from '@nauth-toolkit/nestjs';

@Controller('auth')
export class AuthController {
constructor(private readonly authService: AuthService) {}

@Post('/signup')
async signup(@Body() dto: SignupDTO): Promise<AuthResponseDTO> {
// DTO automatically validated by NestJS
return this.authService.signup(dto);
}
}

Validation

All DTOs use class-validator decorators for automatic validation:

  • Email - @IsEmail() validates email format
  • UUID - @IsUUID('4') validates UUID v4 format
  • Phone - @Matches() validates E.164 format
  • Length - @Length(), @MinLength(), @MaxLength() enforce string length
  • Numbers - @IsNumberString() for numeric strings
  • Required - @IsNotEmpty() for required fields
  • Optional - @IsOptional() for optional fields

Validation errors are automatically converted to NAuthException with VALIDATION_FAILED code.