Express JS Tutorial - Middleware for Authentication| API Security | CheezyCode

preview_player
Показать описание
NodeJS ExpressJS crash course in Hindi. In this tutorial, learn what are middlewares in express js, concept of middleware by comparing it with real life examples. Learn how to create a simple middleware for logging requests. This video covers how to create a middleware for authentication. In this middleware, we will be checking the JWT token and decrypt it using JsonWebTokens Library. Once token is verified, users will be to access other endpoints.

In this Express JS course, we will building complete Rest API using express framework. Complete tutorial covering - Authentication using JWT, Mongoose for Mongo DB with deployment using Heroku.

Topics covered -
1. Concept of Middleware in Express JS.
2. Middleware to log incoming requests in express api.
3. Authentication middleware to check the existence of valid tokens.

Learn how to create APIs by following this tutorial step by step. Everything is explained in Hindi (हिन्दी).

Complete Dependency Injection Playlist Link -

Complete Android Architecture Components Playlist -

Beginner series in Android Playlist (Hindi) -

Kotlin Beginners Tutorial Series -

For more info - visit the below link

We are social. Follow us at -
Рекомендации по теме
Комментарии
Автор

Every gap in express here I am getting fulfilled. Thanks from my heart.

techdular
Автор

in middleware, i am confused but see your video is too good. i am learning from your video sir thanks. if have any problem than I will comment to you.

Narendra
Автор

bro seriously you giving information in easy way so that all can understand. i didnot seen anyone explaining complicated steps in soo easy way. thank you brother continue your efforts. we support you

Lailesh_
Автор

very nice video sir your teaching skill is awesome. I am learning concepts very clearly from you.

theashutoshshukl
Автор

wow, it's an amazing explanation in this short video. Thank you so much

barunkumarpal
Автор

very clearly explained thank you for this very useful video content

smitrakholiya
Автор

You are my lifesaver. I got a job because of you. Is there any tutorial where I can learn to upload videos to a server like BunnyCDN where I have to pass information in headers? I need it for Android.

bhaktibirachan
Автор

nice video sir. your way of teaching awesome. clear every concept

techvibe
Автор

really nice explanation .... it would be great if you could share the code in each video

AbhishekPatil-jnhk
Автор

nice video just with the audio was in English.

milescolon
Автор

Nice video.. waiting for the next video to see how the bearer would be passed in the API call 😊

vikramin
Автор

Is there any video of front end of that also?

malikabdurrehman
Автор

Should i always pass token as header? Can i just pass it via the body of post request?

syedhannan
Автор

for ejs or templete we have to use cookie ?

ADayWithDev
Автор

res.status(401).json({ error: 'Token is invalid.' });
^

TypeError: Cannot read property 'status' of undefined

uguur
Автор

please sir make more video on express js

techvibe
Автор

I'm having an issue with auth middleware. So whenever I send request without the token, app crashes and I get this error.

"Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client

[nodemon] app crashed - waiting for file changes before starting..."

If I remove else condition in auth.js. Then it works but catch response doesn't work and either I get empty array in notes get request or "Something went wrong" error for note create request, which is coming from controller.

I removed try catch block and just tried "if (token) {} else { res.status...}" but still same. app crahsed error. The code is exactly same. Any idea what am I doing wrong?

const jwt = require("jsonwebtoken");
const SECRET_KEY = "notesAPI";

const auth = (req, res, next) => {
try {
let token = req.headers.authorization;

if (token) {
token = token.split(" ")[1];
let user = jwt.verify(token, SECRET_KEY);
req.userId = user.id;
}
else {
res.status(401).json({ message: "Unauthorized User."})
}
next();

} catch (error) {
console.log(error);
res.status(401).json({ message: "Unauthorized User."})
}

}

module.exports = auth;

Nekoeye
Автор

this is not jwt, i means it is completely exploitable and there is no security, even after the tempering the token data is coming and there is no expiration nor token validations . and tempering token also working !

MadarDoraeMon
Автор

Bro es ka code githup per bi add karo..githup ka link to send hi ni keya ap ne?

malikbhai
Автор

Jwt malformed error me crach de raha hai can you help me?

dhanrajmakwana