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

@ -1 +1 @@
module.exports = require("./src/security/sessions")
module.exports = require("./src/security/sessions")

View File

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

View File

@ -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) {

View File

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

View File

@ -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

View File

@ -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