This commit is contained in:
2025-11-13 06:16:55 +01:00
parent e6b4b09277
commit 90c36f2345
28 changed files with 145 additions and 75 deletions
@@ -5,35 +5,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = getAuthCookieNames;
const get_csrf_header_name_1 = __importDefault(require("../../../actions/get-csrf-header-name"));
const app_names_1 = require("../../../dict/app-names");
const grab_db_names_1 = __importDefault(require("../../../utils/grab-db-names"));
/**
* # Grab Auth Cookie Names
*/
function getAuthCookieNames(params) {
var _a, _b;
const cookiesPrefix = process.env.DSQL_COOKIES_PREFIX || "dsql_";
const cookiesKeyName = process.env.DSQL_COOKIES_KEY_NAME || "key";
const cookiesCSRFName = (0, get_csrf_header_name_1.default)();
const cookieOneTimeCodeName = process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME || "one-time-code";
const targetDatabase = ((_a = params === null || params === void 0 ? void 0 : params.database) === null || _a === void 0 ? void 0 : _a.replace(new RegExp(`^${app_names_1.AppNames["DsqlDbPrefix"]}\\d+_`), "")) ||
((_b = process.env.DSQL_DB_NAME) === null || _b === void 0 ? void 0 : _b.replace(new RegExp(`^${app_names_1.AppNames["DsqlDbPrefix"]}\\d+_`), ""));
const { dbSlug } = (0, grab_db_names_1.default)({ dbName: params === null || params === void 0 ? void 0 : params.database });
let keyCookieName = cookiesPrefix;
if (params === null || params === void 0 ? void 0 : params.userId)
keyCookieName += `user_${params.userId}_`;
if (targetDatabase)
keyCookieName += `${targetDatabase}_`;
if (dbSlug)
keyCookieName += `${dbSlug}_`;
keyCookieName += cookiesKeyName;
let csrfCookieName = cookiesPrefix;
if (params === null || params === void 0 ? void 0 : params.userId)
csrfCookieName += `user_${params.userId}_`;
if (targetDatabase)
csrfCookieName += `${targetDatabase}_`;
if (dbSlug)
csrfCookieName += `${dbSlug}_`;
csrfCookieName += cookiesCSRFName;
let oneTimeCodeName = cookiesPrefix;
if (params === null || params === void 0 ? void 0 : params.userId)
oneTimeCodeName += `user_${params.userId}_`;
if (targetDatabase)
oneTimeCodeName += `${targetDatabase}_`;
if (dbSlug)
oneTimeCodeName += `${dbSlug}_`;
oneTimeCodeName += cookieOneTimeCodeName;
return {
keyCookieName,