|
|
|
|
@ -9,6 +9,7 @@ function toIsoSql(d: Date): string {
|
|
|
|
|
|
|
|
|
|
export const handle: Handle = async ({ event, resolve }) => {
|
|
|
|
|
// Sesión por cookie 'sid'
|
|
|
|
|
const isLogout = event.url.pathname === '/api/logout' || event.url.pathname.startsWith('/api/logout/');
|
|
|
|
|
const sid = event.cookies.get('sid');
|
|
|
|
|
if (sid) {
|
|
|
|
|
try {
|
|
|
|
|
@ -48,17 +49,19 @@ export const handle: Handle = async ({ event, resolve }) => {
|
|
|
|
|
} catch {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Refrescar cookie (idle)
|
|
|
|
|
event.cookies.set('sid', sid, {
|
|
|
|
|
path: '/',
|
|
|
|
|
httpOnly: true,
|
|
|
|
|
sameSite: 'lax',
|
|
|
|
|
secure: isProd(),
|
|
|
|
|
maxAge: Math.floor(sessionIdleTtlMs / 1000)
|
|
|
|
|
});
|
|
|
|
|
// Refrescar cookie (idle) excepto durante /api/logout
|
|
|
|
|
if (!isLogout) {
|
|
|
|
|
event.cookies.set('sid', sid, {
|
|
|
|
|
path: '/',
|
|
|
|
|
httpOnly: true,
|
|
|
|
|
sameSite: 'lax',
|
|
|
|
|
secure: isProd(),
|
|
|
|
|
maxAge: Math.floor(sessionIdleTtlMs / 1000)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Sesión inválida/expirada
|
|
|
|
|
event.cookies.delete('sid', { path: '/' });
|
|
|
|
|
event.cookies.delete('sid', { path: '/', httpOnly: true, sameSite: 'lax', secure: isProd() });
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
// En caso de error de DB, no romper la request; continuar sin sesión
|
|
|
|
|
|