@foal/jwt
Version:
Authentication with JWT for FoalTS
32 lines (31 loc) • 1.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeAuthCookie = removeAuthCookie;
const core_1 = require("@foal/core");
const constants_1 = require("./constants");
function removeAuthCookie(response) {
const cookieName = core_1.Config.get('settings.jwt.cookie.name', 'string', constants_1.JWT_DEFAULT_COOKIE_NAME);
const csrfEnabled = core_1.Config.get('settings.jwt.csrf.enabled', 'boolean', false);
let sameSite = core_1.Config.get('settings.jwt.cookie.sameSite', 'string');
if (csrfEnabled && sameSite === undefined) {
sameSite = constants_1.JWT_DEFAULT_SAME_SITE_ON_CSRF_ENABLED;
}
const options = {
domain: core_1.Config.get('settings.jwt.cookie.domain', 'string'),
maxAge: 0,
path: core_1.Config.get('settings.jwt.cookie.path', 'string', constants_1.JWT_DEFAULT_COOKIE_PATH),
sameSite,
secure: core_1.Config.get('settings.jwt.cookie.secure', 'boolean'),
};
response.setCookie(cookieName, '', {
...options,
httpOnly: core_1.Config.get('settings.jwt.cookie.httpOnly', 'boolean'),
});
if (csrfEnabled) {
const csrfCookieName = core_1.Config.get('settings.jwt.csrf.cookie.name', 'string', constants_1.JWT_DEFAULT_CSRF_COOKIE_NAME);
response.setCookie(csrfCookieName, '', {
...options,
httpOnly: false,
});
}
}