UNPKG

@foal/jwt

Version:

Authentication with JWT for FoalTS

33 lines (32 loc) 1.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.removeAuthCookie = void 0; 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, }); } } exports.removeAuthCookie = removeAuthCookie;