Update config variables and add nodemailer's ones

This commit is contained in:
rui hildt 2020-08-29 10:48:21 +02:00
parent f8af75d7d3
commit 2b4832a4f7
6 changed files with 22 additions and 10 deletions

View File

@ -1,7 +1,13 @@
module.exports = {
jwt_secret: process.env.JWT_SECRET,
// from '.env' in root folder
port: process.env.PORT || 3001,
db_url: process.env.DATABASE_URL,
environment: process.env.NODE_ENV || 'development',
dbURL: process.env.DATABASE_URL,
jwtSecret: process.env.JWT_SECRET,
smtpHost: process.env.SMTP_HOST,
smtpPort: process.env.SMTP_PORT,
smtpUsername: process.env.SMTP_USERNAME,
smtpPassword: process.env.SMTP_PASSWORD,
// Others
saltingRounds: process.env.SALTING_ROUNDS || 10,
};

View File

@ -1,5 +1,5 @@
const jwt = require('jsonwebtoken');
const { jwt_secret } = require('../config/config');
const { jwtSecret } = require('../config/config');
function generateToken(user) {
const payload = {
@ -11,7 +11,7 @@ function generateToken(user) {
expiresIn: '30d',
};
return jwt.sign(payload, jwt_secret, options);
return jwt.sign(payload, jwtSecret, options);
}
exports.generateToken = generateToken;

View File

@ -1,10 +1,10 @@
require('dotenv').config();
const { db_url } = require('./config/config');
const { dbURL } = require('./config/config');
module.exports = {
development: {
client: 'pg',
connection: db_url,
connection: dbURL,
migrations: {
directory: './data/migrations',
},
@ -14,7 +14,7 @@ module.exports = {
testing: {
client: 'pg',
connection: db_url,
connection: dbURL,
migrations: {
directory: './data/migrations',
},
@ -24,7 +24,7 @@ module.exports = {
production: {
client: 'pg',
connection: db_url,
connection: dbURL,
migrations: {
directory: './data/migrations',
},

View File

@ -1,11 +1,11 @@
const jwt = require('jsonwebtoken');
const { jwt_secret } = require('../config/config');
const { jwtSecret } = require('../config/config');
function authenticate(req, res, next) {
const token = req.get('Authorization');
if (token) {
jwt.verify(token, jwt_secret, (err, decoded) => {
jwt.verify(token, jwtSecret, (err, decoded) => {
if (err) return res.status(401).json(err);
req.decoded = decoded;
next();

5
package-lock.json generated
View File

@ -1428,6 +1428,11 @@
"resolved": "https://registry.npmjs.org/nocache/-/nocache-2.1.0.tgz",
"integrity": "sha512-0L9FvHG3nfnnmaEQPjT9xhfN4ISk0A8/2j4M37Np4mcDesJjHgEUfgPhdCyZuFI954tjokaIj/A3NdpFNdEh4Q=="
},
"nodemailer": {
"version": "6.4.11",
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.4.11.tgz",
"integrity": "sha512-BVZBDi+aJV4O38rxsUh164Dk1NCqgh6Cm0rQSb9SK/DHGll/DrCMnycVDD7msJgZCnmVa8ASo8EZzR7jsgTukQ=="
},
"normalize-package-data": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz",

View File

@ -22,6 +22,7 @@
"helmet": "^3.22.0",
"jsonwebtoken": "^8.5.1",
"knex": "^0.21.1",
"nodemailer": "^6.4.11",
"pg": "^8.0.3",
"pgtools": "^0.3.0",
"uuid": "^8.0.0"