Skip to content

Commit

Permalink
fixed-bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
kalpana Kumari authored and kalpana Kumari committed Aug 3, 2024
1 parent 9bfc205 commit 7152e14
Show file tree
Hide file tree
Showing 215 changed files with 7,437 additions and 1,860 deletions.
8 changes: 8 additions & 0 deletions backend/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
MONGO_URI="mongodb+srv://KmKalpana:[email protected]/inventory-app?retryWrites=true&w=majority"
NODE_ENV=production
JWT_SECRET=kalpana123
EMAIL_HOST=smtp.gmail.com
EMAIL_USER=[email protected]
EMAIL_PASS='dfnwhkyimnlpbjsb'
FRONTEND_URL=http://localhost:3000
CLOUDINARY_URL=cloudinary://559995642867967:_txMnqqNG7K44VUWkmv88CPYclk@kalpanakathait
2 changes: 0 additions & 2 deletions backend/.gitignore

This file was deleted.

3 changes: 1 addition & 2 deletions backend/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ const changePassword = asyncHandler(async (req, res) => {

// Create Reset Token
let resetToken = crypto.randomBytes(32).toString("hex") + user._id;
console.log(resetToken);


// Hash token before saving to DB
const hashedToken = crypto
Expand Down Expand Up @@ -271,7 +271,6 @@ const changePassword = asyncHandler(async (req, res) => {
try {
await sendEmail(subject, message, send_to, sent_from);
res.status(200).json({ success: true, message: "Reset Email Sent" });
//console.log(message)
} catch (error) {
res.status(500);
throw new Error("Email not sent, please try again");
Expand Down
57 changes: 29 additions & 28 deletions backend/middleWare/authmiddleWare.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
const asyncHandler = require("express-async-handler");
const User = require("../models/userModel");
const jwt = require("jsonwebtoken");
const bcrypt = require("bcryptjs");
const protect= asyncHandler(async(req,res,next)=>{
try {
const token=req.cookies.token;
if(!token)
{
res.status(401)
throw new Error("Not Authorized, please Login.")
}
//Verify Token
// @ts-ignore
const verified = jwt.verify(token, process.env.jwt_SECRET)
//get user id from token
const user = await User.findById(verified.id).select("-password")
if(!user)
{
res.status(401)
throw new Error("Not Authorized, please Login.")
}
// @ts-ignore
req.user=user
next()
} catch (error) {
res.status(401)
throw new Error("Not Authorized, please Login.")
}
})
module.exports=protect;

const protect = asyncHandler(async (req, res, next) => {
try {
const token = req.cookies.token;
if (!token) {
res.status(401);
throw new Error("Not Authorized, please Login.");
}

// Verify Token
const verified = jwt.verify(token, process.env.JWT_SECRET);

// Get user from token
const user = await User.findById(verified.id).select("-password");
if (!user) {
res.status(401);
throw new Error("Not Authorized, please Login.");
}

// Attach user to request object
req.user = user;
next();
} catch (error) {
res.status(401);
throw new Error("Not Authorized, please Login.");
}
});

module.exports = protect;
12 changes: 0 additions & 12 deletions backend/node_modules/.bin/nodemon

This file was deleted.

1 change: 1 addition & 0 deletions backend/node_modules/.bin/nodemon

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7152e14

Please sign in to comment.