NestJS Authentication: JWTs, Sessions, logins, and more! | NestJS PassportJS Tutorial

NestJS Authentication: JWTs, Sessions, logins, and more! | NestJS PassportJS Tutorial

Marius Espejo

54 года назад

167,960 Просмотров

In this video we'll discuss the fundamentals of adding authentication to your NestJS API. We'll talk about utilizing passport to use different types of authentication strategies. Specifically we will try the passport-local strategy as a basic login with username and password example. Next, we'll take a look at potentially using sessions to store user information and persist their login state. Finally we will also take a look at a state-less approach with JSON Web Tokens (JWTs). We'll create our own JWTs and I'll show you how you can use that to protect your API routes!

00:00 - Intro
03:35 - Initial routes
04:41 - UsersService
07:50 - AuthService
10:40 - Implementing passport-local strategy (username/password login)
18:08 - AuthGuards
23:25 - Summary of local login flow
29:02 - Guard to check if user is authenticated
31:41 - Setting up sessions
40:37 - Summary of login with sessions flow
44:25 - Setting up JWT strategy, signing and validating
1:00:25 - Summary of JWT strategy flow
1:04:22 - Conclusion
1:05:20 - Outro

Тэги:

#nest #javascript #nestjs #nestjs_tutorial #nestjs_auth #nestjs_authentication #nestjs_authentication_jwt #jwt #jwt_authentication #jwt_token #jwt_security #express_session #express_session_node_js #passport_js #node_passport #passportjs #node_auth #authentication #node #passport_js_jwt #passport_js_tutorial #passport_js_google #passport_js_react #nestjs_passport #nestjs_passport_jwt #passport_local_strategy_nodejs #passport_local_strategy #nestjs_passport_local #nestjs_guards
Ссылки и html тэги не поддерживаются


Комментарии:

@AliAliOxenFree
@AliAliOxenFree - 13.02.2023 02:11

this is an excellent video. your explanation is spot on. thank you for taking the time to make these

Ответить
@asogbaibrahim9618
@asogbaibrahim9618 - 13.02.2023 19:54

I love this tutorial. Clear as Spring water 💯

Ответить
@yazelkro7522
@yazelkro7522 - 17.02.2023 00:17

Hello, I have covered the first 30 minutes of the video, I keep getting this when using postman TypeError: Cannot read properties of undefined (reading 'validateUser'). I do not find the error, I have checked the documentation

Ответить
@toneyavuz8389
@toneyavuz8389 - 19.02.2023 14:35

I haven't seen that you edited the main.ts file.

Ответить
@aben7810
@aben7810 - 24.02.2023 15:44

over separation of concerns. thanks for the tutorial anyway. I don't know why Nest is making everything complicated, yet people enjoying it, frankly.

Ответить
@bossmusa9075
@bossmusa9075 - 03.03.2023 03:35

Even today i remember how i asked the question below the similar type of video about jwt and you reply back really fast althought your video was already great. As i see you still answers the questions and its impresive.

Ответить
@quamzgraphix9826
@quamzgraphix9826 - 04.03.2023 04:38

your nest js contents are soo good. keep it up marius

Ответить
@bigg565
@bigg565 - 05.03.2023 17:27

When I finish the local strategy without tokens or jwt first, I constantly get a 401 Error and that I am unauthorized, do You maybe know why and can help me out?

Ответить
@ashishkumari-yg4gn
@ashishkumari-yg4gn - 13.03.2023 13:38

Thank you sir

Ответить
@mickomagallanes1185
@mickomagallanes1185 - 18.03.2023 11:13

Thank you Marius, building a NestJS Login with MikroORM alone is a huge pain for me, is it possible to get the source code of this tutorial?

Ответить
@profx53
@profx53 - 13.04.2023 18:35

Hi, will you add this code to the github?

Ответить
@kobakamladze4175
@kobakamladze4175 - 26.05.2023 13:06

Thank you for your effort!

Ответить
@wakibtz7134
@wakibtz7134 - 26.05.2023 20:28

how can i take a user information on client if i make session based auth? I get session id in cookie but what i can make with it

Ответить
@JawwadNissar
@JawwadNissar - 13.06.2023 14:52

you did amazing job. plz tell one thing. how to implement authentication on microservice based architecture

Ответить
@vulezor
@vulezor - 27.06.2023 21:03

Oh man, you should use the database the whole trick is within that.

Ответить
@carlosteixeira4304
@carlosteixeira4304 - 30.06.2023 23:37

Great tutorial bro. It's easy undestandable even to a beginner like me. Nice Job!

Ответить
@johnparungao1354
@johnparungao1354 - 28.07.2023 10:13

What are the reasons you chose React over Angular? knowing nestjs is literally angular but backend ?

Ответить
@kennethflores1434
@kennethflores1434 - 29.07.2023 23:08

anyone know why i am getting the [Nest] 36853 - 07/29/2023, 4:05:01 PM ERROR [ExceptionsHandler] secretOrPrivateKey must have a value.?

I have followed this tutorial to the tea and cannot get it. I have implemented env but it DOES come out with the value when i console log it. Any pointers?

Ответить
@pronaxking1918
@pronaxking1918 - 03.08.2023 15:12

What if I have multiple strategy.ts files for the same Strategy for passport. How would i let Passport know which file to use when!

Ответить
@thomasdaquinzomahounhele8889
@thomasdaquinzomahounhele8889 - 05.08.2023 22:41

thank you very much, your work is clear and it is very easy to follow you through the whole video

Ответить
@devbel
@devbel - 08.08.2023 19:05

Great one 👌 Thanks

Ответить
@canmertinyo
@canmertinyo - 10.08.2023 14:46

Thanks :)

Ответить
@tecno_davo
@tecno_davo - 25.08.2023 06:24

Great video! It helps me a lot, thank you!

Ответить
@ali-d-coded5620
@ali-d-coded5620 - 31.08.2023 18:47

you should make a video on serving html in nestjs like to create a dashboard html/htmx

Ответить
@mochamadrasyad338
@mochamadrasyad338 - 06.09.2023 18:11

Awesome !! 🔥🔥, Thank you very much

Ответить
@abubakarsani3463
@abubakarsani3463 - 07.09.2023 17:04

This is excellent

Ответить
@gameplay_factory
@gameplay_factory - 07.09.2023 18:29

does JWT works with session ?

Ответить
@maxbraun6271
@maxbraun6271 - 10.09.2023 04:54

Great video thank you!

Ответить
@visualbonus8880
@visualbonus8880 - 14.09.2023 00:01

This was awesome!

Ответить
@Fakhranyy
@Fakhranyy - 02.10.2023 14:20

Great work ! , but I was wondering , it's too many steps I think I couldn't all of these from my memory , I think it's hard at first and it's okay if I followed the documentation to implement it .. what's your opinion about that ?
all love from Egypt <3

Ответить
@s1dev
@s1dev - 02.10.2023 17:43

How to make old jwt expire when making a new one?

Ответить
@e.magnoneto5101
@e.magnoneto5101 - 16.10.2023 22:09

Hiiii, i´m super excited to learn more about nest.js, is a such framework. May u can give me one tip, how do i use this session savinf user, and jwt at redis in a graphql API, is the same process? what i need change to works? thank u soo much for that incredible channel, i also follow u in linkendin. Bye

Ответить
@argya2073
@argya2073 - 13.11.2023 16:28

thank you marius, your are awesome

Ответить
@MahmoudAhmed-nq7ou
@MahmoudAhmed-nq7ou - 18.01.2024 06:19

(this.validate is not a function) this error had shown to me
can someone help me please

Ответить
@waycambas150
@waycambas150 - 15.02.2024 01:46

I got some error when request protected

ERROR [ExceptionsHandler] Unknown authentication strategy "jwt"
Error: Unknown authentication strategy "jwt"

Ответить
@dalmiro2h
@dalmiro2h - 25.02.2024 04:35

this a have a circular dependency dont?

Ответить
@josipkes
@josipkes - 04.03.2024 16:19

Extremely valuable content, thanks.

Ответить
@axelle9764
@axelle9764 - 11.03.2024 09:59

Great tutorial! Very detail and useful. Keep up the good work

Ответить
@hasst9261
@hasst9261 - 06.04.2024 23:29

Cool content
Rly helpful
Ty!

Ответить
@damianroszak335
@damianroszak335 - 16.04.2024 11:21

👍

Ответить
@vanshdubey21
@vanshdubey21 - 14.05.2024 13:33

VERY VERY HELPFUL VIDEO

Ответить
@mohabedr5030
@mohabedr5030 - 08.06.2024 19:48

bro with this approach the user need to register and then login, we should be able to register and automatically login

Ответить
@Randito33
@Randito33 - 25.08.2024 22:07

Thanks for this tutorial, I went through the NestJS docs a few times and tried to set this up myself but there was always something wrong. Your vid helped me finally get it all working!

Ответить
@JorgeFrota-r6w
@JorgeFrota-r6w - 29.08.2024 04:15

Hey Marius, just passing by to thank you, your video format is awesome.
I love how you explain everything while showing the documentation. It really adds to us as developers, so that we know like "oh, so the information was here all the time!". It particularly helped me a lot.

Keep up the good work!

Ответить
@uafkhurram
@uafkhurram - 01.09.2024 10:16

source code please...

Ответить
@seal0118
@seal0118 - 13.10.2024 11:45

why do not provide guards in the auth module? are they provided internally by nest?

Ответить
@jackw4150
@jackw4150 - 04.12.2024 10:29

please share the github repo

Ответить
@mariusespejo
@mariusespejo - 28.02.2022 06:16

Note: a lot of people are getting the error “request.isAuthenticated is not a function”. Please note that I explicitly mentioned in the video that it will not work until you properly setup sessions. If you run into that error, KEEP watching! The problem will resolve itself once you have the full setup, don’t stop at the point of error. If you watch the rest of the video and still have this problem, double check that you properly configured and registered your strategies and guards exactly as shown in the video.

Ответить