Updating environment in auth package, easily see required env settings.

This commit is contained in:
mike12345567 2021-04-14 14:13:48 +01:00
parent eef989f375
commit e580628b9c
6 changed files with 21 additions and 11 deletions

View File

@ -1,8 +1,9 @@
const PouchDB = require("pouchdb") const PouchDB = require("pouchdb")
const env = require("../environment")
// level option is purely for testing (development) // level option is purely for testing (development)
const COUCH_DB_URL = const COUCH_DB_URL =
process.env.COUCH_DB_URL || "http://budibase:budibase@localhost:10000/db/" env.COUCH_DB_URL || "http://budibase:budibase@localhost:10000/db/"
const Pouch = PouchDB.defaults({ const Pouch = PouchDB.defaults({
prefix: COUCH_DB_URL, prefix: COUCH_DB_URL,

View File

@ -0,0 +1,8 @@
module.exports = {
JWT_SECRET: process.env.JWT_SECRET,
COUCH_DB_URL: process.env.COUCH_DB_URL,
SALT_ROUNDS: process.env.SALT_ROUNDS,
GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID,
GOOGLE_CLIENT_SECRET: process.env.GOOGLE_CLIENT_SECRET,
GOOGLE_AUTH_CALLBACK_URL: process.env.GOOGLE_AUTH_CALLBACK_URL,
}

View File

@ -1,6 +1,7 @@
const bcrypt = require("bcryptjs") const bcrypt = require("bcryptjs")
const env = require("./environment")
const SALT_ROUNDS = process.env.SALT_ROUNDS || 10 const SALT_ROUNDS = env.SALT_ROUNDS || 10
exports.hash = async data => { exports.hash = async data => {
const salt = await bcrypt.genSalt(SALT_ROUNDS) const salt = await bcrypt.genSalt(SALT_ROUNDS)

View File

@ -1,10 +1,9 @@
// const CouchDB = require("../db") const env = require("../../environment")
exports.options = { exports.options = {
clientId: process.env.GOOGLE_CLIENT_ID, clientId: env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET, clientSecret: env.GOOGLE_CLIENT_SECRET,
callbackURL: process.env.GOOGLE_AUTH_CALLBACK_URL, callbackURL: env.GOOGLE_AUTH_CALLBACK_URL,
// "http://localhost:" + (process.env.PORT || 3000) + "/auth/google/callback",
} }
exports.authenticate = async function(token, tokenSecret, profile, done) { exports.authenticate = async function(token, tokenSecret, profile, done) {

View File

@ -1,7 +1,8 @@
const { Cookies } = require("../../constants") const { Cookies } = require("../../constants")
const env = require("../../environment")
exports.options = { exports.options = {
secretOrKey: process.env.JWT_SECRET, secretOrKey: env.JWT_SECRET,
jwtFromRequest: function(ctx) { jwtFromRequest: function(ctx) {
return ctx.cookies.get(Cookies.Auth) return ctx.cookies.get(Cookies.Auth)
}, },

View File

@ -3,6 +3,7 @@ const { UserStatus } = require("../../constants")
const CouchDB = require("../../db") const CouchDB = require("../../db")
const { StaticDatabases, generateUserID } = require("../../db/utils") const { StaticDatabases, generateUserID } = require("../../db/utils")
const { compare } = require("../../hashing") const { compare } = require("../../hashing")
const env = require("../../environment")
const INVALID_ERR = "Invalid Credentials" const INVALID_ERR = "Invalid Credentials"
@ -40,13 +41,12 @@ exports.authenticate = async function(username, password, done) {
const payload = { const payload = {
userId: dbUser._id, userId: dbUser._id,
builder: dbUser.builder, builder: dbUser.builder,
email: dbUser.email,
} }
const token = jwt.sign(payload, process.env.JWT_SECRET, { dbUser.token = jwt.sign(payload, env.JWT_SECRET, {
expiresIn: "1 day", expiresIn: "1 day",
}) })
dbUser.token = token
// Remove users password in payload // Remove users password in payload
delete dbUser.password delete dbUser.password