dsql-admin/dsql-app/package-shared/functions/backend/cookies/get-auth-cookie-names.js
Benjamin Toby 86f931fb82 Updates
2024-12-08 09:57:48 +01:00

32 lines
995 B
JavaScript

// @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";
let keyCookieName = cookiesPrefix;
if (params?.userId) keyCookieName += `user_${params.userId}_`;
if (params?.database) keyCookieName += `${params.database}_`;
keyCookieName += cookiesKeyName;
let csrfCookieName = cookiesPrefix;
if (params?.userId) csrfCookieName += `user_${params.userId}_`;
if (params?.database) csrfCookieName += `${params.database}_`;
csrfCookieName += cookiesCSRFName;
return {
keyCookieName,
csrfCookieName,
};
};