cityssm/parking-ticket-system

View on GitHub
helpers/functions.session.js

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import { getSafeRedirectURL } from './functions.authentication.js';
import { getConfigProperty } from './functions.config.js';
const sessionCookieName = getConfigProperty('session.cookieName');
export function sessionHandler(request, response, next) {
    if (hasActiveSession(request)) {
        next();
        return;
    }
    const redirectUrl = getSafeRedirectURL(request.originalUrl);
    response.redirect(`${getConfigProperty('reverseProxy.urlPrefix')}/login?redirect=${encodeURIComponent(redirectUrl)}`);
}
export function hasActiveSession(request) {
    return (Object.hasOwn(request.session, 'user') &&
        Object.hasOwn(request.cookies, sessionCookieName));
}