// @ts-check /** * # Grab Auth Cookie Names * * @param {object} [params] * @param {string} [params.database] * @param {string | number} [params.userId] * * @returns {{ keyCookieName: string, csrfCookieName: string }} */ module.exports = function getAuthCookieNames(params) { const cookiesPrefix = process.env.DSQL_COOKIES_PREFIX || "dsql_"; const cookiesKeyName = process.env.DSQL_COOKIES_KEY_NAME || "key"; const cookiesCSRFName = process.env.DSQL_COOKIES_CSRF_NAME || "csrf"; const targetDatabase = params?.database || process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/, ""); let keyCookieName = cookiesPrefix; if (params?.userId) keyCookieName += `user_${params.userId}_`; if (targetDatabase) keyCookieName += `${targetDatabase}_`; keyCookieName += cookiesKeyName; let csrfCookieName = cookiesPrefix; if (params?.userId) csrfCookieName += `user_${params.userId}_`; if (targetDatabase) csrfCookieName += `${targetDatabase}_`; csrfCookieName += cookiesCSRFName; return { keyCookieName, csrfCookieName, }; };