diff --git a/components/settings/OrganizationSettings.tsx b/components/settings/OrganizationSettings.tsx index 9c766ec..d017f44 100644 --- a/components/settings/OrganizationSettings.tsx +++ b/components/settings/OrganizationSettings.tsx @@ -177,8 +177,8 @@ export default function OrganizationSettings() { if (auditStartDate) params.start_date = auditStartDate if (auditEndDate) params.end_date = auditEndDate const { entries, total } = await getAuditLog(params) - setAuditEntries(entries) - setAuditTotal(total) + setAuditEntries(Array.isArray(entries) ? entries : []) + setAuditTotal(typeof total === 'number' ? total : 0) } catch (error) { console.error('Failed to load audit log', error) toast.error(getAuthErrorMessage(error as Error) || 'Failed to load audit log') @@ -842,7 +842,7 @@ export default function OrganizationSettings() {
Loading audit log... - ) : auditEntries.length === 0 ? ( + ) : (auditEntries ?? []).length === 0 ? (
No audit events found.
) : (
@@ -857,7 +857,7 @@ export default function OrganizationSettings() { - {auditEntries.map((entry) => ( + {(auditEntries ?? []).map((entry) => ( {new Date(entry.occurred_at).toLocaleString()} diff --git a/lib/api/audit.ts b/lib/api/audit.ts index 7335543..45671f1 100644 --- a/lib/api/audit.ts +++ b/lib/api/audit.ts @@ -55,6 +55,7 @@ async function auditFetch(endpoint: string, options: RequestInit = {}): Promi /** * Fetches paginated audit log entries for the current org (org from JWT; admin-only on backend). + * Normalizes response so entries is always an array (backend may return null when empty). */ export async function getAuditLog(params: GetAuditLogParams = {}): Promise { const search = new URLSearchParams() @@ -65,5 +66,9 @@ export async function getAuditLog(params: GetAuditLogParams = {}): Promise(url, { method: 'GET' }) + const data = await auditFetch(url, { method: 'GET' }) + return { + entries: Array.isArray(data?.entries) ? data.entries : [], + total: typeof data?.total === 'number' ? data.total : 0, + } }