@@ -3,7 +3,12 @@ import { getUserById } from "~/models/user.server";
33import { sanitizeRedirectPath } from "~/utils" ;
44import { authenticator } from "./auth.server" ;
55import { getImpersonationId } from "./impersonation.server" ;
6- import { getEffectiveSessionDuration , isSessionExpired } from "./sessionDuration.server" ;
6+ import { logger } from "./logger.server" ;
7+ import {
8+ getEffectiveSessionDuration ,
9+ getSessionIssuedAt ,
10+ isSessionExpired ,
11+ } from "./sessionDuration.server" ;
712import { getUserSession } from "./sessionStorage.server" ;
813
914export async function getUserId ( request : Request ) : Promise < string | undefined > {
@@ -29,8 +34,22 @@ export async function getUserId(request: Request): Promise<string | undefined> {
2934 // by the most restrictive Organization.maxSessionDuration). If the session
3035 // was issued longer ago than the cap allows, force a logout.
3136 const session = await getUserSession ( request ) ;
32- const { durationSeconds } = await getEffectiveSessionDuration ( authUser . userId ) ;
37+ const { durationSeconds, orgCapSeconds, userSettingSeconds } = await getEffectiveSessionDuration (
38+ authUser . userId
39+ ) ;
3340 if ( isSessionExpired ( session , durationSeconds ) ) {
41+ const issuedAt = getSessionIssuedAt ( session ) ;
42+ // HIPAA audit trail: structured log lands in CloudWatch via stdout. Use
43+ // the stable `event` field to filter/aggregate auto-logout events.
44+ logger . info ( "Auto-logout: session exceeded effective duration" , {
45+ event : "session.auto_logout" ,
46+ userId : authUser . userId ,
47+ effectiveDurationSeconds : durationSeconds ,
48+ userSettingSeconds,
49+ orgCapSeconds,
50+ sessionAgeMs : issuedAt === null ? null : Date . now ( ) - issuedAt ,
51+ requestPath : new URL ( request . url ) . pathname ,
52+ } ) ;
3453 throw redirect ( "/logout" ) ;
3554 }
3655
0 commit comments