38 lines
1.7 KiB
JavaScript
38 lines
1.7 KiB
JavaScript
import getCsrfHeaderName from "../../../actions/get-csrf-header-name";
|
|
import { AppNames } from "../../../dict/app-names";
|
|
/**
|
|
* # Grab Auth Cookie Names
|
|
*/
|
|
export default 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 = getCsrfHeaderName();
|
|
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(`^${AppNames["DsqlDbPrefix"]}\\d+_`), "")) ||
|
|
((_b = process.env.DSQL_DB_NAME) === null || _b === void 0 ? void 0 : _b.replace(new RegExp(`^${AppNames["DsqlDbPrefix"]}\\d+_`), ""));
|
|
let keyCookieName = cookiesPrefix;
|
|
if (params === null || params === void 0 ? void 0 : params.userId)
|
|
keyCookieName += `user_${params.userId}_`;
|
|
if (targetDatabase)
|
|
keyCookieName += `${targetDatabase}_`;
|
|
keyCookieName += cookiesKeyName;
|
|
let csrfCookieName = cookiesPrefix;
|
|
if (params === null || params === void 0 ? void 0 : params.userId)
|
|
csrfCookieName += `user_${params.userId}_`;
|
|
if (targetDatabase)
|
|
csrfCookieName += `${targetDatabase}_`;
|
|
csrfCookieName += cookiesCSRFName;
|
|
let oneTimeCodeName = cookiesPrefix;
|
|
if (params === null || params === void 0 ? void 0 : params.userId)
|
|
oneTimeCodeName += `user_${params.userId}_`;
|
|
if (targetDatabase)
|
|
oneTimeCodeName += `${targetDatabase}_`;
|
|
oneTimeCodeName += cookieOneTimeCodeName;
|
|
return {
|
|
keyCookieName,
|
|
csrfCookieName,
|
|
oneTimeCodeName,
|
|
};
|
|
}
|