parent
58f43356fa
commit
833fd11d51
|
@ -1,15 +0,0 @@
|
||||||
import dotenv from 'dotenv';
|
|
||||||
import _ from 'lodash';
|
|
||||||
|
|
||||||
const result = dotenv.config();
|
|
||||||
|
|
||||||
let envs;
|
|
||||||
|
|
||||||
if (!('error' in result)) {
|
|
||||||
envs = result.parsed;
|
|
||||||
} else {
|
|
||||||
envs = {};
|
|
||||||
_.each(process.env, (value, key) => envs[key] = value);
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = envs;
|
|
|
@ -5,7 +5,6 @@ const auth = require("../middleware/auth");
|
||||||
const User = require("../schemas/User");
|
const User = require("../schemas/User");
|
||||||
const config = require("config");
|
const config = require("config");
|
||||||
|
|
||||||
import { jwtSecret } from '../config/config';
|
|
||||||
|
|
||||||
router.post("/register", async (req, res) => {
|
router.post("/register", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
@ -61,8 +60,7 @@ router.post("/login", async (req, res) => {
|
||||||
const isMatch = await bcrypt.compare(password, user.password);
|
const isMatch = await bcrypt.compare(password, user.password);
|
||||||
if (!isMatch) return res.status(400).json({ msg: "Invalid credentials." });
|
if (!isMatch) return res.status(400).json({ msg: "Invalid credentials." });
|
||||||
|
|
||||||
//const token = jwt.sign({ id: user._id },config.get('jwtSecret'));
|
const token = jwt.sign({ id: user._id },config.get('jwtSecret'));
|
||||||
const token = jwt.sign({ id: user._id }, jwtSecret);
|
|
||||||
if(token) return res
|
if(token) return res
|
||||||
.json({
|
.json({
|
||||||
token,
|
token,
|
||||||
|
|
|
@ -2,7 +2,6 @@ const express = require("express");
|
||||||
const config = require("config");
|
const config = require("config");
|
||||||
const mongoose = require("mongoose");
|
const mongoose = require("mongoose");
|
||||||
const cors = require("cors");
|
const cors = require("cors");
|
||||||
import { mongoURI } from './config/config';
|
|
||||||
|
|
||||||
// set up express
|
// set up express
|
||||||
|
|
||||||
|
@ -17,8 +16,7 @@ app.listen(PORT, () => console.log(`The server has started on port: ${PORT}`));
|
||||||
// set up mongoose
|
// set up mongoose
|
||||||
|
|
||||||
mongoose.connect(
|
mongoose.connect(
|
||||||
//config.get('mongoURI'),
|
config.get('mongoURI'),
|
||||||
mongoURI,
|
|
||||||
{
|
{
|
||||||
useNewUrlParser: true,
|
useNewUrlParser: true,
|
||||||
useUnifiedTopology: true,
|
useUnifiedTopology: true,
|
||||||
|
|
Loading…
Reference in New Issue