Skip to content

Commit

Permalink
adding env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
harshbaldwa committed Sep 1, 2019
1 parent 99423c3 commit 9315243
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
7 changes: 3 additions & 4 deletions backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ const check_auth = require('./check_auth');

const app = express();

mongoose //YnwLdH8guBV9EOam
mongoose
.connect(
//"mongodb://ladder:YnwLdH8guBV9EOam@cluster0-shard-00-00-cvuiq.mongodb.net:27017,cluster0-shard-00-01-cvuiq.mongodb.net:27017,cluster0-shard-00-02-cvuiq.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true&w=majority"
"mongodb://localhost:27017/myapp"
"mongodb://ladder:YnwLdH8guBV9EOam@cluster0-shard-00-00-cvuiq.mongodb.net:27017,cluster0-shard-00-01-cvuiq.mongodb.net:27017,cluster0-shard-00-02-cvuiq.mongodb.net:27017/myLadder?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true&w=majority"
)
.then(() => {
console.log("Connected to database!");
Expand Down Expand Up @@ -713,7 +712,7 @@ app.post("/api/login", (req, res, next) => {
}
const token = jwt.sign(
{ roll: fetchedPlayer.roll, playerId: fetchedPlayer._id },
"harsh_is_god_he_is_invincible"
process.env.JWT_KEY
);
res.status(200).json({
token: token,
Expand Down
2 changes: 1 addition & 1 deletion backend/check_auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const jwt = require("jsonwebtoken");
module.exports = (req, res, next) => {
try {
const token = req.headers.authorization.split(" ")[1];
jwt.verify(token, "harsh_is_god_he_is_invincible");
jwt.verify(token, process.env.JWT_KEY);
next();
} catch (error) {
res.status(401).json({ message: "Auth failed!" });
Expand Down
6 changes: 6 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"env": {
"MONGO_ATLAS_PW": "YnwLdH8guBV9EOam",
"JWT_KEY": "harsh_is_god_he_is_invincible"
}
}

0 comments on commit 9315243

Please sign in to comment.