Smart Library Docs

Audit Endpoints

API reference for security audit log retrieval — paginated, filterable audit trail for admin oversight.

Audit Endpoints

View the security audit trail. All authentication events (login, logout, token refresh, security events) are logged automatically and can be queried through this endpoint.

Base Path: /api/v1/audit

All endpoints require authentication and ROLE_ADMIN authorization.


Get Audit Logs

GET /api/v1/audit

Returns a paginated list of audit log entries, sorted by newest first. Supports filtering by action type.

Authorization: ROLE_ADMIN only

Query Parameters

ParameterTypeDefaultDescription
actionStringFilter by action type: LOGIN, LOGOUT, TOKEN_REFRESH, TOKEN_REVOKED, SECURITY_EVENT
limitNumber100Results per page (max)
pageNumber1Page number

Success Response — 200 OK

{
  "logs": [
    {
      "_id": "...",
      "action": "LOGIN",
      "status": "SUCCESS",
      "userId": {
        "firstName": "John",
        "lastName": "Doe",
        "email": "john@example.com",
        "rollNumber": "CS2024001",
        "role": "ROLE_STUDENT"
      },
      "ipAddress": "192.168.1.1",
      "userAgent": "Mozilla/5.0 ...",
      "details": null,
      "createdAt": "2026-07-06T21:00:00.000Z"
    }
  ],
  "pagination": {
    "total": 245,
    "page": 1,
    "limit": 100,
    "totalPages": 3
  }
}

Audit Action Types

ActionDescription
LOGINUser login attempt (success or failure)
LOGOUTUser logout
TOKEN_REFRESHAccess token refresh via refresh token
TOKEN_REVOKEDToken manually revoked
SECURITY_EVENTSystem security events (e.g., cron job failures)

Audit Status Values

StatusDescription
SUCCESSThe action completed successfully
FAILUREThe action failed (e.g., invalid password, expired token)

Route Summary

MethodPathAuthDescription
GET/auditAdmin onlyGet paginated audit logs

Note: Audit logs are write-only from the application's perspective. They are created automatically by the auditLogger utility and cannot be modified or deleted through the API.

On this page