Comments (2)
Remove "next" from line number 18
from youtube2022.
The issue is with the callback function for VerifyToken in verifyUser and verifyAdmin. The "next" parameter must be removed from the verifyToken function calls (not from the verifyToken's definition) to prevent it from directly going to the next middleware.
import jwt from "jsonwebtoken";
import createError from "../utils/error.js";
export const verifyToken = (req, res, next) => {
console.log("VerifyToken Called!");
const token = req.cookies.access_token;
if (!token) return next(createError(401, "You are not authenticated!"));
jwt.verify(token, process.env.JWT, (err, user) => {
if (err) return next(createError(403, "Token is not valid!"));
req.user = user;
next();
})
}
export const verifyUser = (req, res, next) => {
console.log("VerifyUser Called!");
verifyToken(req, res, () => {
console.log("VerifyUser Callback function called!")
if (req.user.id === req.params.id || req.user.isAdmin) {
console.log("User verified!");
next();
} else {
return next(createError(403, "You are not authorized!"));
}
});
};
export const verifyAdmin = (req, res, next) => {
console.log("VerifyAdmin Called!");
verifyToken(req, res, () => {
console.log("VerifyAdmin Callback function called!")
if (req.user.isAdmin) {
next();
} else {
return next(createError(403, "You are not authorized!"));
}
});
};
from youtube2022.
Related Issues (20)
- Login Route is mistaken HOT 1
- Internet connection and using then on the social-app branch (React)
- React, NodeJs, MySQL: Request failed with status code 404', name: 'AxiosError' HOT 1
- req cookies not working on vite HOT 1
- Can use validations
- Blog App - Unhandled Thrown Error! Objects are not valid as a React child (found: object with keys {code, fatal}). If you meant to render a collection of children, use an array instead. HOT 1
- Error once trying to login - Blog APP
- Lama
- Lama
- Product Page setselected issue
- when im writing git conel --single-branch -b react-admin https://github.com/safak/youtube2022.git HOT 2
- Related to git HOT 3
- Related to video Page HOT 1
- Start file is missing in Script HOT 1
- Missing Script start HOT 1
- Missing Repositories
- POST http://localhost:8800/api/auth/register [HTTP/1.1 500 Internal Server Error ...AxiosError@http://localhost:3000/static HOT 7
- When trying to text input something in chat, this is what I get... HOT 1
- Not able to hit the API : HOT 3
- (0 , react__WEBPACK_IMPORTED_MODULE_1__.useEffect) is not a function HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from youtube2022.