Updates
This commit is contained in:
+9
-5
@@ -20,6 +20,7 @@ const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names")
|
||||
const api_login_1 = __importDefault(require("../../functions/api/users/api-login"));
|
||||
const get_auth_cookie_names_1 = __importDefault(require("../../functions/backend/cookies/get-auth-cookie-names"));
|
||||
const write_auth_files_1 = require("../../functions/backend/auth/write-auth-files");
|
||||
const debug_log_1 = __importDefault(require("../../utils/logging/debug-log"));
|
||||
/**
|
||||
* # Login A user
|
||||
*/
|
||||
@@ -36,6 +37,9 @@ function loginUser(_a) {
|
||||
: undefined;
|
||||
const finalEncryptionKey = encryptionKey || process.env.DSQL_ENCRYPTION_PASSWORD;
|
||||
const finalEncryptionSalt = encryptionSalt || process.env.DSQL_ENCRYPTION_SALT;
|
||||
function debugFn(log, label) {
|
||||
(0, debug_log_1.default)({ log, addTime: true, title: "loginUser", label });
|
||||
}
|
||||
if (!(finalEncryptionKey === null || finalEncryptionKey === void 0 ? void 0 : finalEncryptionKey.match(/.{8,}/))) {
|
||||
console.log("Encryption key is invalid");
|
||||
return {
|
||||
@@ -148,7 +152,7 @@ function loginUser(_a) {
|
||||
});
|
||||
}
|
||||
if (debug) {
|
||||
console.log(`loginUser:httpResponse:`, httpResponse);
|
||||
debugFn(httpResponse, "httpResponse");
|
||||
}
|
||||
if (httpResponse === null || httpResponse === void 0 ? void 0 : httpResponse.success) {
|
||||
let encryptedPayload = (0, encrypt_1.default)({
|
||||
@@ -173,16 +177,16 @@ function loginUser(_a) {
|
||||
const authKeyName = cookieNames.keyCookieName;
|
||||
const csrfName = cookieNames.csrfCookieName;
|
||||
if (debug) {
|
||||
console.log(`loginUser:authKeyName:`, authKeyName);
|
||||
console.log(`loginUser:csrfName:`, csrfName);
|
||||
console.log(`loginUser:encryptedPayload:`, encryptedPayload);
|
||||
debugFn(authKeyName, "authKeyName");
|
||||
debugFn(csrfName, "csrfName");
|
||||
debugFn(encryptedPayload, "encryptedPayload");
|
||||
}
|
||||
response === null || response === void 0 ? void 0 : response.setHeader("Set-Cookie", [
|
||||
`${authKeyName}=${encryptedPayload};samesite=strict;path=/;HttpOnly=true;Secure=true`,
|
||||
`${csrfName}=${(_b = httpResponse.payload) === null || _b === void 0 ? void 0 : _b.csrf_k};samesite=strict;path=/;HttpOnly=true`,
|
||||
]);
|
||||
if (debug) {
|
||||
console.log(`loginUser:Response Sent!`);
|
||||
debugFn("Response Sent!");
|
||||
}
|
||||
}
|
||||
return httpResponse;
|
||||
|
||||
+6
-2
@@ -10,6 +10,7 @@ const ejson_1 = __importDefault(require("../../utils/ejson"));
|
||||
const write_auth_files_1 = require("../../functions/backend/auth/write-auth-files");
|
||||
const parseCookies_1 = __importDefault(require("../../utils/backend/parseCookies"));
|
||||
const grab_host_names_1 = __importDefault(require("../../utils/grab-host-names"));
|
||||
const debug_log_1 = __importDefault(require("../../utils/logging/debug-log"));
|
||||
/**
|
||||
* # Logout user
|
||||
*/
|
||||
@@ -25,8 +26,11 @@ function logoutUser({ response, database, dsqlUserId, encryptedUserString, reque
|
||||
database,
|
||||
userId: user_id,
|
||||
});
|
||||
function debugFn(log, label) {
|
||||
(0, debug_log_1.default)({ log, addTime: true, title: "logoutUser", label });
|
||||
}
|
||||
if (debug) {
|
||||
console.log("logoutUser:cookieNames", cookieNames);
|
||||
debugFn(cookieNames, "cookieNames");
|
||||
}
|
||||
const authKeyName = cookieNames.keyCookieName;
|
||||
const csrfName = cookieNames.csrfCookieName;
|
||||
@@ -57,7 +61,7 @@ function logoutUser({ response, database, dsqlUserId, encryptedUserString, reque
|
||||
}
|
||||
})();
|
||||
if (debug) {
|
||||
console.log("logoutUser:decryptedUserJSON", decryptedUserJSON);
|
||||
debugFn(decryptedUserJSON, "decryptedUserJSON");
|
||||
}
|
||||
if (!decryptedUserJSON)
|
||||
throw new Error("Invalid User");
|
||||
|
||||
Reference in New Issue
Block a user