This commit is contained in:
Benjamin Toby
2025-01-14 14:58:44 +01:00
parent f181b79ef7
commit 62bb1fd6d4
8 changed files with 24 additions and 16 deletions
+12 -4
View File
@@ -14,6 +14,7 @@ type Param = {
cookieString?: string;
database?: string;
dsqlUserId?: string | number;
debug?: boolean;
};
type Return = {
@@ -32,6 +33,7 @@ export default function logoutUser({
encryptedUserString,
request,
cookieString,
debug,
}: Param): Return {
/**
* Check Encryption Keys
@@ -44,9 +46,13 @@ export default function logoutUser({
userId: dsqlUserId || process.env.DSQL_API_USER_ID,
});
if (debug) {
console.log("logoutUser:cookieNames", cookieNames);
}
const authKeyName = cookieNames.keyCookieName;
const csrfName = cookieNames.csrfCookieName;
const oneTimeCodeName = getAuthCookieNames().oneTimeCodeName;
const oneTimeCodeName = cookieNames.oneTimeCodeName;
const decryptedUserJSON: string | undefined = (() => {
try {
@@ -75,6 +81,10 @@ export default function logoutUser({
}
})();
if (debug) {
console.log("logoutUser:decryptedUserJSON", decryptedUserJSON);
}
if (!decryptedUserJSON) throw new Error("Invalid User");
const userObject = EJSON.parse(
@@ -98,7 +108,7 @@ export default function logoutUser({
msg: "User Logged Out",
cookieNames,
};
} catch (/** @type {any} */ error: any) {
} catch (error: any) {
console.log("Logout Error:", error.message);
return {
success: false,
@@ -106,5 +116,3 @@ export default function logoutUser({
};
}
}
module.exports = logoutUser;