From 0f2ae76bbc733ea96eb9ac7b455979af0563b7a6 Mon Sep 17 00:00:00 2001 From: Tben <52448020+BenjaminToby@users.noreply.github.com> Date: Sat, 24 Jun 2023 16:05:14 +0100 Subject: [PATCH] updates --- package.json | 3 +-- users/logout-user.js | 14 ++++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index bc76adb..fc19038 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "datasquirel", - "version": "1.1.52", + "version": "1.1.53", "description": "Cloud-based SQL data management tool", "main": "index.js", "scripts": { @@ -13,7 +13,6 @@ "keywords": [ "SQL", "Cloud", - "Cloud", "Storage", "API", "Data", diff --git a/users/logout-user.js b/users/logout-user.js index cdbfd51..50483d5 100644 --- a/users/logout-user.js +++ b/users/logout-user.js @@ -6,20 +6,26 @@ const parseCookies = require("../utils/functions/parseCookies"); * @param {object} params - Single Param object containing params * @param {object} params.request - Http request object * @param {object} params.response - Http response object + * @param {string} params.database - Target database name(slug) * * @returns {{success: boolean, payload: string}} */ -module.exports = function ({ request, response }) { +module.exports = function ({ request, response, database }) { /** * Check Encryption Keys * * @description Check Encryption Keys */ try { - const cookiesKeys = Object.keys(parseCookies({ request })); + const cookies = parseCookies({ request }); + const cookiesKeys = Object.keys(cookies); - const authKeyName = cookiesKeys.filter((cookieKey) => cookieKey.match(/datasquirel_.*_auth_key/))[0]; - const csrfName = cookiesKeys.filter((cookieKey) => cookieKey.match(/datasquirel_.*_csrf/))[0]; + const dbUid = cookies.dsqluid; + const keyRegexp = new RegExp(`datasquirel_${dbUid}_${database}_auth_key`); + const csrfRegexp = new RegExp(`datasquirel_${dbUid}_${database}_csrf`); + + const authKeyName = cookiesKeys.filter((cookieKey) => cookieKey.match(keyRegexp))[0]; + const csrfName = cookiesKeys.filter((cookieKey) => cookieKey.match(csrfRegexp))[0]; response.setHeader("Set-Cookie", [`${authKeyName}=null;samesite=strict;path=/;HttpOnly=true;Secure=true`, `${csrfName}=null;samesite=strict;path=/;HttpOnly=true`, `dsqluid=null;samesite=strict;path=/;HttpOnly=true`]);