'use server' import { getSession } from '@admin/auth/middleware' import db from '@admin/db' import { auditLog } from '@admin/db/schema' import { and, desc, eq, sql } from 'drizzle-orm' export async function getPasswordChangedAt(): Promise { const session = await getSession() if (!session?.user) { return null } try { const rows = await db .select({ createdAt: auditLog.createdAt }) .from(auditLog) .where( and( eq(auditLog.actorUserId, session.user.id), eq(auditLog.category, 'auth'), eq(auditLog.action, 'update'), sql`${auditLog.metadata} ->> 'operation' = 'password_change'` ) ) .orderBy(desc(auditLog.createdAt)) .limit(1) return rows[0]?.createdAt ?? null } catch (error) { console.error('Failed to load the password change date:', error) return null } }