GetUserDevicesDTO
Package: @nauth-toolkit/core
Type: DTO (Request/Response)
Data transfer objects for getting all MFA devices configured for a user.
- NestJS
- Express
- Fastify
import {
GetUserDevicesDTO,
AdminGetUserDevicesDTO,
GetUserDevicesResponseDTO
} from '@nauth-toolkit/nestjs';
import {
GetUserDevicesDTO,
AdminGetUserDevicesDTO,
GetUserDevicesResponseDTO
} from '@nauth-toolkit/core';
import {
GetUserDevicesDTO,
AdminGetUserDevicesDTO,
GetUserDevicesResponseDTO
} from '@nauth-toolkit/core';
GetUserDevicesDTO (Self-Service Request)
Used for self-service device retrieval. User is obtained from the authenticated context.
| Property | Type | Required | Description |
|---|---|---|---|
| (none) | - | - | User obtained from authenticated context |
AdminGetUserDevicesDTO (Admin Request)
Used for admin operations to retrieve devices for a specific user.
| Property | Type | Required | Description |
|---|---|---|---|
sub | string | Yes | Target user's unique identifier |
Validation:
subis required and must be a non-empty string
GetUserDevicesResponseDTO (Response)
| Property | Type | Description |
|---|---|---|
devices | MFADeviceResponseDTO[] | Array of user's MFA devices |
Each device contains:
| Property | Type | Description |
|---|---|---|
id | number | Device ID |
type | MFADeviceMethod | Device type (totp, sms, email, passkey) |
name | string | Device name |
isPreferred | boolean | Whether this is the preferred device |
isActive | boolean | Whether the device is active |
createdAt | Date | Device 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
- MFAService.getUserDevices() - Self-service
- MFAService.adminGetUserDevices() - Admin operation
Related DTOs
- AdminGetUserDevicesDTO - Admin request DTO (requires
sub) - RemoveDeviceDTO - Remove a device by ID
- SetPreferredDeviceDTO - Set preferred device