Fixing session issues after testing a bit.

This commit is contained in:
mike12345567 2021-07-07 17:15:53 +01:00
parent b8928077e2
commit 79b7747714
6 changed files with 14 additions and 8 deletions

View File

@ -4,7 +4,6 @@ const redis = require("../redis/authRedis")
const EXPIRY_SECONDS = 3600 const EXPIRY_SECONDS = 3600
exports.getUser = async userId => { exports.getUser = async userId => {
const client = await redis.getUserClient() const client = await redis.getUserClient()
// try cache // try cache

View File

@ -49,13 +49,14 @@ module.exports = (noAuthPatterns = [], opts) => {
internal = false internal = false
if (authCookie) { if (authCookie) {
let error = null let error = null
const sessionId = authCookie.sessionId, userId = authCookie.userId const sessionId = authCookie.sessionId,
userId = authCookie.userId
const session = await getSession(userId, sessionId) const session = await getSession(userId, sessionId)
if (!session) { if (!session) {
error = "No session found" error = "No session found"
} else { } else {
try { try {
const user = await getUser(userId) user = await getUser(userId)
delete user.password delete user.password
authenticated = true authenticated = true
} catch (err) { } catch (err) {

View File

@ -1,4 +1,5 @@
const { Client, utils } = require("./index") const Client = require("./index")
const utils = require("./utils")
let userClient, sessionClient let userClient, sessionClient

View File

@ -1,7 +1,12 @@
const env = require("../environment") const env = require("../environment")
// ioredis mock is all in memory // ioredis mock is all in memory
const Redis = env.isTest() ? require("ioredis-mock") : require("ioredis") 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 RETRY_PERIOD_MS = 2000
const STARTUP_TIMEOUT_MS = 5000 const STARTUP_TIMEOUT_MS = 5000

View File

@ -2,7 +2,6 @@ const { getAppId, setCookie, getCookie, clearCookie } =
require("@budibase/auth").utils require("@budibase/auth").utils
const { Cookies } = require("@budibase/auth").constants const { Cookies } = require("@budibase/auth").constants
const { getRole } = require("@budibase/auth/roles") const { getRole } = require("@budibase/auth/roles")
const { getGlobalSelf } = require("../utilities/workerRequests")
const { BUILTIN_ROLE_IDS } = require("@budibase/auth/roles") const { BUILTIN_ROLE_IDS } = require("@budibase/auth/roles")
const { generateUserMetadataID } = require("../db/utils") const { generateUserMetadataID } = require("../db/utils")
const { dbExists } = require("@budibase/auth/db") 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) { if (!ctx.user) {
// not logged in, try to set a cookie for public apps // not logged in, try to set a cookie for public apps
appId = requestAppId appId = requestAppId