From 4da665efd46a375ad65ad7c5720dec5abd29a123 Mon Sep 17 00:00:00 2001 From: Tben Date: Mon, 7 Aug 2023 05:10:45 +0100 Subject: [PATCH] Type Checking --- package.json | 2 +- users/logout-user.js | 2 +- users/user-auth.js | 7 ++++--- utils/functions/parseCookies.js | 9 ++++++--- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index c22b5e9..3ab9a38 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "datasquirel", - "version": "1.2.5", + "version": "1.2.6", "description": "Cloud-based SQL data management tool", "main": "index.js", "scripts": { diff --git a/users/logout-user.js b/users/logout-user.js index b945ac9..93c96c5 100644 --- a/users/logout-user.js +++ b/users/logout-user.js @@ -54,7 +54,7 @@ function logoutUser({ request, response, database }) { /** ********************************************** */ /** ********************************************** */ } catch (error) { - console.log(error.message); + console.log(error); return { success: false, diff --git a/users/user-auth.js b/users/user-auth.js index a2f0032..bb5f192 100644 --- a/users/user-auth.js +++ b/users/user-auth.js @@ -5,6 +5,7 @@ * Imports * ============================================================================== */ +const http = require("http"); const decrypt = require("../functions/decrypt"); const parseCookies = require("../utils/functions/parseCookies"); @@ -19,7 +20,7 @@ const parseCookies = require("../utils/functions/parseCookies"); * @typedef {object} AuthenticatedUserObject * @property {boolean} success - Did the function run successfully? * @property {import("../types/user.td").DATASQUIREL_LoggedInUser | null} payload - Payload - * @property {string} [msg] - Response Message + * @property {string | unknown} [msg] - Response Message */ /** @@ -29,7 +30,7 @@ const parseCookies = require("../utils/functions/parseCookies"); * with the user's data * * @param {Object} params - Arg - * @param {Object} params.request - Http request object + * @param {http.IncomingMessage} params.request - Http request object * @param {String} params.encryptionKey - Encryption Key * @param {String} params.encryptionSalt - Encryption Salt * @param {String} params.level - Optional. "Deep" value indicates an extra layer of security @@ -130,7 +131,7 @@ function userAuth({ request, encryptionKey, encryptionSalt, level, database }) { return { success: false, payload: null, - msg: error.message, + msg: error, }; } } diff --git a/utils/functions/parseCookies.js b/utils/functions/parseCookies.js index 39b2593..a25a857 100644 --- a/utils/functions/parseCookies.js +++ b/utils/functions/parseCookies.js @@ -1,8 +1,11 @@ +// @ts-check + /** * ============================================================================== * Imports * ============================================================================== */ +const http = require("http"); /** * Parse request cookies @@ -13,9 +16,9 @@ * @async * * @param {object} params - main params object - * @param {object} params.request - HTTPS request object + * @param {http.IncomingMessage} params.request - HTTPS request object * - * @returns {object|null} + * @returns {* | null} */ module.exports = function ({ request }) { /** @@ -28,7 +31,7 @@ module.exports = function ({ request }) { //////////////////////////////////////// //////////////////////////////////////// - /** @type {string|null} */ + /** @type {string | undefined} */ const cookieString = request.headers.cookie; if (!cookieString || typeof cookieString !== "string") {