mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-09-02 21:58:06 +00:00
fix(auth): keep active sessions alive and add stay-signed-in (#1711)
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
import type { Request } from 'express';
|
||||
import { SESSION_COOKIE_MAX_AGE_MS } from './constants';
|
||||
|
||||
/** True when the request arrived over HTTPS, either directly or via a trusted TLS-terminating proxy. */
|
||||
export const isSecureRequest = (req: Request): boolean => {
|
||||
return req.secure || req.headers['x-forwarded-proto'] === 'https';
|
||||
};
|
||||
|
||||
/** Cookie options derived from the current request (secure flag follows the connection). */
|
||||
/**
|
||||
* Cookie options derived from the current request (secure flag follows the
|
||||
* connection). Lifetime is deliberately not included: each caller sets its own
|
||||
* `maxAge` (session cookies vary between the default and "stay signed in", the
|
||||
* MFA-pending cookie is minutes long), so a shared default here would only ever
|
||||
* be overridden or misread.
|
||||
*/
|
||||
export const getCookieOptions = (req: Request) => ({
|
||||
httpOnly: true,
|
||||
secure: isSecureRequest(req),
|
||||
sameSite: 'strict' as const,
|
||||
maxAge: SESSION_COOKIE_MAX_AGE_MS,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user