-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kalpana Kumari
authored and
kalpana Kumari
committed
Aug 3, 2024
1 parent
9bfc205
commit 7152e14
Showing
215 changed files
with
7,437 additions
and
1,860 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.