archetecture security fix

This commit is contained in:
root
2026-06-11 03:22:12 -04:00
parent 6def9993da
commit 9483750161
3126 changed files with 177194 additions and 37211 deletions
+31
View File
@@ -0,0 +1,31 @@
import type { Response } from 'express'
import type { ActorType } from './tokens'
const COOKIE_NAMES: Record<ActorType, string> = {
admin: 'admin_session',
employee: 'employee_session',
renter: 'renter_session',
}
export function getSessionCookieName(actorType: ActorType) {
return COOKIE_NAMES[actorType]
}
export function setSessionCookie(res: Response, actorType: ActorType, token: string, maxAgeMs?: number) {
res.cookie(getSessionCookieName(actorType), token, {
httpOnly: true,
secure: process.env.NODE_ENV === 'production',
sameSite: actorType === 'admin' ? 'strict' : 'lax',
path: '/',
maxAge: maxAgeMs,
})
}
export function clearSessionCookie(res: Response, actorType: ActorType) {
res.clearCookie(getSessionCookieName(actorType), {
httpOnly: true,
secure: process.env.NODE_ENV === 'production',
sameSite: actorType === 'admin' ? 'strict' : 'lax',
path: '/',
})
}