Fixing some issues with auth module.

This commit is contained in:
mike12345567 2021-04-15 16:57:01 +01:00
parent 9e1315c535
commit af53ed2109
5 changed files with 12 additions and 21 deletions

View File

@ -1,9 +1,5 @@
let Pouch
module.exports.getDB = () => {
return Pouch
}
module.exports.setDB = pouch => {
Pouch = pouch
module.exports.CouchDB = pouch
}
module.exports.CouchDB = null

View File

@ -1,9 +1,8 @@
const db = require("./db")
const passport = require("koa-passport")
const LocalStrategy = require("passport-local").Strategy
const JwtStrategy = require("passport-jwt").Strategy
// const GoogleStrategy = require("passport-google-oauth").Strategy
const CouchDB = require("./db")
const database = require("./db")
const { StaticDatabases } = require("./db/utils")
const { jwt, local, authenticated } = require("./middleware")
const { Cookies, UserStatus } = require("./constants")
@ -29,7 +28,7 @@ passport.use(new JwtStrategy(jwt.options, jwt.authenticate))
passport.serializeUser((user, done) => done(null, user))
passport.deserializeUser(async (user, done) => {
const db = new CouchDB(StaticDatabases.USER.name)
const db = new database.CouchDB(StaticDatabases.USER.name)
try {
const user = await db.get(user._id)
@ -42,7 +41,7 @@ passport.deserializeUser(async (user, done) => {
module.exports = {
init(pouch) {
db.setDB(pouch)
database.setDB(pouch)
},
passport,
Cookies,

View File

@ -1,6 +1,6 @@
const jwt = require("jsonwebtoken")
const { UserStatus } = require("../../constants")
const CouchDB = require("../../db")
const database = require("../../db")
const { StaticDatabases, generateUserID } = require("../../db/utils")
const { compare } = require("../../hashing")
const env = require("../../environment")
@ -21,7 +21,7 @@ exports.authenticate = async function(username, password, done) {
if (!password) return done(null, false, "Password Required.")
// Check the user exists in the instance DB by email
const db = new CouchDB(StaticDatabases.USER.name)
const db = new database.CouchDB(StaticDatabases.USER.name)
let dbUser
try {

View File

@ -1,5 +1,7 @@
// need to load environment first
const env = require("./environment")
const CouchDB = require("./db")
require("@budibase/auth").init(CouchDB)
const Koa = require("koa")
const destroyable = require("server-destroy")
const electron = require("electron")
@ -11,10 +13,6 @@ 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()

View File

@ -1,5 +1,7 @@
// need to load environment first
const env = require("./environment")
const CouchDB = require("./db")
require("@budibase/auth").init(CouchDB)
const Koa = require("koa")
const destroyable = require("server-destroy")
const koaBody = require("koa-body")
@ -7,10 +9,6 @@ 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()