feat(auth): enhance security and audit logging
- Integrate webhook alerts for admin login lockouts. - Implement detailed audit logging for login, logout, and setup actions. - Improve client revocation event tracking. - Standardize error handling in profile updates. - Enforce 'operator' role for event API access.
This commit is contained in:
1 parent
5c977d6977
commit
8132087085
52 files changed
+4434
-407
No files matched your search
@@ -1,8 +1,10 @@
|
||||
import { getSessionCookieOptions } from "@/core/auth/adminSession";
|
||||
import { recordAdminAuditLogAsync } from "@/core/auth/auditLog";
|
||||
import {
|
||||
revokeAdminSessions,
|
||||
verifyRequestAdminSession,
|
||||
} from "@/core/auth/adminUsers";
|
||||
import { extractClientIp } from "@/lib/adminAuth";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
const SESSION_COOKIE = "datastack_admin_session";
|
||||
@@ -13,7 +15,20 @@ export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const check = await verifyRequestAdminSession(token);
|
||||
if (check.valid) {
|
||||
await revokeAdminSessions();
|
||||
await revokeAdminSessions({
|
||||
memberId: check.session.memberId,
|
||||
email: check.session.email,
|
||||
});
|
||||
await recordAdminAuditLogAsync({
|
||||
actorEmail: check.session.email,
|
||||
actorRole: check.session.role || "owner",
|
||||
action: "ADMIN_LOGOUT",
|
||||
target: check.session.email,
|
||||
ipAddress: extractClientIp(request),
|
||||
metadata: {
|
||||
memberId: check.session.memberId || "owner-1",
|
||||
},
|
||||
});
|
||||
}
|
||||
} catch {
|
||||
// Still clear client cookie even if server revocation encounters transient DB error
|
||||
|
||||
Reference in new issue
Block a user