Skip to main content

AuthAuditService

Package: @nauth-toolkit/core Type: Service

Query authentication and security audit events for monitoring and investigation.

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

Overview

Use this service to query the authentication audit trail (login attempts, MFA events, suspicious activity, and risk-assessment markers). Audit event recording is internal.

Methods

getEventsByType()

Get events by type with pagination.

async getEventsByType(dto: GetEventsByTypeDTO): Promise<GetEventsByTypeResponseDTO>

Parameters

Errors

None.

Returns

Example

const result = await this.auditService.getEventsByType({
eventType: AuthAuditEventType.SUSPICIOUS_ACTIVITY,
page: 1,
limit: 100,
startDate: new Date('2026-01-01'),
});

getRiskAssessmentHistory()

Get risk assessment history for adaptive MFA analysis.

async getRiskAssessmentHistory(dto: GetRiskAssessmentHistoryDTO): Promise<GetRiskAssessmentHistoryResponseDTO>

Parameters

Errors

Throws NAuthException with code:

CodeWhenDetails
NOT_FOUNDUser not foundundefined

Returns

Example

const result = await this.auditService.getRiskAssessmentHistory({
sub: 'user-uuid',
limit: 50,
});

getSuspiciousActivity()

Get suspicious activity events.

async getSuspiciousActivity(dto: GetSuspiciousActivityDTO): Promise<GetSuspiciousActivityResponseDTO>

Parameters

Errors

Throws NAuthException with code:

CodeWhenDetails
NOT_FOUNDUser not foundundefined

Returns

Example

const result = await this.auditService.getSuspiciousActivity({
sub: 'user-uuid',
limit: 50,
});

getUserAuthHistory()

Get paginated authentication history for a user (admin operation).

async getUserAuthHistory(dto: AdminGetUserAuthHistoryDTO): Promise<GetUserAuthHistoryResponseDTO>

Parameters

Errors

Throws NAuthException with code:

CodeWhenDetails
NOT_FOUNDUser not foundundefined

Returns

Example

@Injectable()
export class MyService {
constructor(private auditService: AuthAuditService) {}

async example() {
const result = await this.auditService.getUserAuthHistory({
sub: 'user-uuid', // Required: target user's sub
page: 1,
limit: 50,
eventTypes: [AuthAuditEventType.LOGIN_SUCCESS],
});
// result.data - IAuthAudit[]
// result.total - number
// result.page - number
// result.limit - number
// result.totalPages - number
}
}