From 79b77477141256b0a71aec61a7a951a66058445a Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 7 Jul 2021 17:15:53 +0100 Subject: [PATCH] Fixing session issues after testing a bit. --- packages/auth/sessions.js | 2 +- packages/auth/src/cache/user.js | 1 - packages/auth/src/middleware/authenticated.js | 5 +++-- packages/auth/src/redis/authRedis.js | 3 ++- packages/auth/src/redis/index.js | 7 ++++++- packages/server/src/middleware/currentapp.js | 4 ++-- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/auth/sessions.js b/packages/auth/sessions.js index f823773797..c07efa2380 100644 --- a/packages/auth/sessions.js +++ b/packages/auth/sessions.js @@ -1 +1 @@ -module.exports = require("./src/security/sessions") \ No newline at end of file +module.exports = require("./src/security/sessions") diff --git a/packages/auth/src/cache/user.js b/packages/auth/src/cache/user.js index aac9f68a3c..46202cbfe9 100644 --- a/packages/auth/src/cache/user.js +++ b/packages/auth/src/cache/user.js @@ -4,7 +4,6 @@ const redis = require("../redis/authRedis") const EXPIRY_SECONDS = 3600 - exports.getUser = async userId => { const client = await redis.getUserClient() // try cache diff --git a/packages/auth/src/middleware/authenticated.js b/packages/auth/src/middleware/authenticated.js index fd65afa744..9afbb33489 100644 --- a/packages/auth/src/middleware/authenticated.js +++ b/packages/auth/src/middleware/authenticated.js @@ -49,13 +49,14 @@ module.exports = (noAuthPatterns = [], opts) => { internal = false if (authCookie) { let error = null - const sessionId = authCookie.sessionId, userId = authCookie.userId + const sessionId = authCookie.sessionId, + userId = authCookie.userId const session = await getSession(userId, sessionId) if (!session) { error = "No session found" } else { try { - const user = await getUser(userId) + user = await getUser(userId) delete user.password authenticated = true } catch (err) { diff --git a/packages/auth/src/redis/authRedis.js b/packages/auth/src/redis/authRedis.js index b7054e7b7c..decce6763b 100644 --- a/packages/auth/src/redis/authRedis.js +++ b/packages/auth/src/redis/authRedis.js @@ -1,4 +1,5 @@ -const { Client, utils } = require("./index") +const Client = require("./index") +const utils = require("./utils") let userClient, sessionClient diff --git a/packages/auth/src/redis/index.js b/packages/auth/src/redis/index.js index 2480b531e7..4f2b5288ea 100644 --- a/packages/auth/src/redis/index.js +++ b/packages/auth/src/redis/index.js @@ -1,7 +1,12 @@ const env = require("../environment") // ioredis mock is all in memory const Redis = env.isTest() ? require("ioredis-mock") : require("ioredis") -const { addDbPrefix, removeDbPrefix, getRedisOptions, SEPARATOR } = require("./utils") +const { + addDbPrefix, + removeDbPrefix, + getRedisOptions, + SEPARATOR, +} = require("./utils") const RETRY_PERIOD_MS = 2000 const STARTUP_TIMEOUT_MS = 5000 diff --git a/packages/server/src/middleware/currentapp.js b/packages/server/src/middleware/currentapp.js index 82d8c1af72..f599fa2bf7 100644 --- a/packages/server/src/middleware/currentapp.js +++ b/packages/server/src/middleware/currentapp.js @@ -2,7 +2,6 @@ const { getAppId, setCookie, getCookie, clearCookie } = require("@budibase/auth").utils const { Cookies } = require("@budibase/auth").constants const { getRole } = require("@budibase/auth/roles") -const { getGlobalSelf } = require("../utilities/workerRequests") const { BUILTIN_ROLE_IDS } = require("@budibase/auth/roles") const { generateUserMetadataID } = require("../db/utils") const { dbExists } = require("@budibase/auth/db") @@ -27,7 +26,8 @@ module.exports = async (ctx, next) => { } } - let appId, roleId = BUILTIN_ROLE_IDS.PUBLIC + let appId, + roleId = BUILTIN_ROLE_IDS.PUBLIC if (!ctx.user) { // not logged in, try to set a cookie for public apps appId = requestAppId