From 9e1315c535b733525f934764f2d4562c5ce36fff Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 15 Apr 2021 16:45:21 +0100 Subject: [PATCH] Updating auth lib so that it takes in a pouch instance rather than creating its own. --- packages/auth/package.json | 3 +-- packages/auth/src/db/index.js | 17 +++++++---------- packages/auth/src/index.js | 4 ++++ packages/server/src/app.js | 4 ++++ packages/worker/src/index.js | 4 ++++ 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/packages/auth/package.json b/packages/auth/package.json index ff59eeb7ba..294b09321d 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -12,7 +12,6 @@ "passport-google-auth": "^1.0.2", "passport-google-oauth": "^2.0.0", "passport-jwt": "^4.0.0", - "passport-local": "^1.0.0", - "pouchdb": "^7.2.2" + "passport-local": "^1.0.0" } } diff --git a/packages/auth/src/db/index.js b/packages/auth/src/db/index.js index 65aa7b4430..2cc033da86 100644 --- a/packages/auth/src/db/index.js +++ b/packages/auth/src/db/index.js @@ -1,12 +1,9 @@ -const PouchDB = require("pouchdb") -const env = require("../environment") +let Pouch -// level option is purely for testing (development) -const COUCH_DB_URL = - env.COUCH_DB_URL || "http://budibase:budibase@localhost:10000/db/" +module.exports.getDB = () => { + return Pouch +} -const Pouch = PouchDB.defaults({ - prefix: COUCH_DB_URL, -}) - -module.exports = Pouch +module.exports.setDB = pouch => { + Pouch = pouch +} diff --git a/packages/auth/src/index.js b/packages/auth/src/index.js index 4e0faf7a72..ca8b092ec4 100644 --- a/packages/auth/src/index.js +++ b/packages/auth/src/index.js @@ -1,3 +1,4 @@ +const db = require("./db") const passport = require("koa-passport") const LocalStrategy = require("passport-local").Strategy const JwtStrategy = require("passport-jwt").Strategy @@ -40,6 +41,9 @@ passport.deserializeUser(async (user, done) => { }) module.exports = { + init(pouch) { + db.setDB(pouch) + }, passport, Cookies, UserStatus, diff --git a/packages/server/src/app.js b/packages/server/src/app.js index 88776fadac..7c015e9d26 100644 --- a/packages/server/src/app.js +++ b/packages/server/src/app.js @@ -11,6 +11,10 @@ const eventEmitter = require("./events") const automations = require("./automations/index") const Sentry = require("@sentry/node") const fileSystem = require("./utilities/fileSystem") +const auth = require("@budibase/auth") +const CouchDB = require("./db") + +auth.init(CouchDB) const app = new Koa() diff --git a/packages/worker/src/index.js b/packages/worker/src/index.js index 55f2705ed1..225547d337 100644 --- a/packages/worker/src/index.js +++ b/packages/worker/src/index.js @@ -7,6 +7,10 @@ const { passport } = require("@budibase/auth") const logger = require("koa-pino-logger") const http = require("http") const api = require("./api") +const auth = require("@budibase/auth") +const CouchDB = require("./db") + +auth.init(CouchDB) const app = new Koa()