Skip to main content

GetUserDevicesDTO

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

Data transfer objects for getting all MFA devices configured for a user.

import { 
GetUserDevicesDTO,
AdminGetUserDevicesDTO,
GetUserDevicesResponseDTO
} from '@nauth-toolkit/nestjs';

GetUserDevicesDTO (Self-Service Request)

Used for self-service device retrieval. User is obtained from the authenticated context.

PropertyTypeRequiredDescription
(none)--User obtained from authenticated context

AdminGetUserDevicesDTO (Admin Request)

Used for admin operations to retrieve devices for a specific user.

PropertyTypeRequiredDescription
substringYesTarget user's unique identifier

Validation:

  • sub is required and must be a non-empty string

GetUserDevicesResponseDTO (Response)

PropertyTypeDescription
devicesMFADeviceResponseDTO[]Array of user's MFA devices

Each device contains:

PropertyTypeDescription
idnumberDevice ID
typeMFADeviceMethodDevice type (totp, sms, email, passkey)
namestringDevice name
isPreferredbooleanWhether this is the preferred device
isActivebooleanWhether the device is active
createdAtDateDevice creation timestamp

Self-Service Example

// Get devices for current authenticated user
const result = await mfaService.getUserDevices({});

Response:

{
"devices": [
{
"id": 1,
"type": "totp",
"name": "Google Authenticator",
"isActive": true,
"isPreferred": true,
"createdAt": "2024-01-01T00:00:00.000Z"
},
{
"id": 2,
"type": "passkey",
"name": "MacBook Pro",
"isActive": true,
"isPreferred": false,
"createdAt": "2024-01-02T00:00:00.000Z"
}
]
}

Admin Example

// Get devices for a specific user (admin only)
const result = await mfaService.adminGetUserDevices({
sub: 'a21b654c-2746-4168-acee-c175083a65cd'
});

Response: Same format as self-service.

Controller Examples

NestJS Self-Service Endpoint

@Get('mfa/devices')
@UseGuards(AuthGuard)
async getMFADevices(): Promise<GetUserDevicesResponseDTO> {
return this.mfaService.getUserDevices({});
}

NestJS Admin Endpoint

@Get('admin/users/:sub/mfa/devices')
@UseGuards(AdminAuthGuard) // Your admin guard
async adminGetUserDevices(
@Param() dto: AdminGetUserDevicesDTO
): Promise<GetUserDevicesResponseDTO> {
return this.mfaService.adminGetUserDevices(dto);
}

Used By