Тёмный

NestJS JWT Authentication Tutorial 

Anson the Developer
Подписаться 50 тыс.
Просмотров 21 тыс.
50% 1

Code Repository: github.com/stuyy/nestjs-passp...
Support the Channel:
Become a Member: ru-vid.com...
Become a Patreon: / stuyy
Buy me a Coffee: ko-fi.com/anson
Donate on Streamlabs: streamlabs.com/ansondevacadem...
Donate on PayPal: paypal.me/ansonfoong
Connect with me:
Twitter: / ansonthedev
Discord: / discord
GitHub: github.com/stuyy
Twitch: / stuy

Хобби

Опубликовано:

 

11 янв 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 65   
@Leon0_0
@Leon0_0 5 месяцев назад
Your videos are absolutely amazing and very informative, just keep up the great work.
@user-jn2rs3rw3x
@user-jn2rs3rw3x 5 месяцев назад
I like your videos about nest, they're unique and really informative!
@_tylerkinney
@_tylerkinney 4 месяца назад
Thank you so frickin much! Needed this for smth I'm working on 👀
@tpzd1063
@tpzd1063 4 месяца назад
Same
@ansonthedev
@ansonthedev 4 месяца назад
You're welcome
@Demo-df2vr
@Demo-df2vr Месяц назад
Awesome tutorial, really helped me out! (Um salve do Brasil pra todo mundo que estiver lendo!)
@se1yagyn
@se1yagyn 27 дней назад
Very well structured video. Very nice explained. A wish from my side would be a Role Base Login now on top of this JWT Login. So an admin will redirect to another place then the regular user in the frontend bases on the login response
@vageeshanvageesh5583
@vageeshanvageesh5583 5 месяцев назад
The king anson is back!!!
@jhoubu
@jhoubu 2 месяца назад
Very good video. Question, what themes do you use in vscode?
@mohsenmostafavi5028
@mohsenmostafavi5028 5 месяцев назад
Awesome I'm excited about next golang video
@dawidgrabowski
@dawidgrabowski 3 месяца назад
Great explanation!
@pierocruz6191
@pierocruz6191 Месяц назад
Quite informative, nice job!
@user-qr6dh7qx8t
@user-qr6dh7qx8t 3 месяца назад
tnx so much, man this video is awesome! U help me alot, dude, I hope u ll make more video, u a best on it
@davilucciola3362
@davilucciola3362 4 месяца назад
Tutorial very good man! Thank you so much! Another brazilian (🇧🇷) here?
@ansonthedev
@ansonthedev 4 месяца назад
Thank you. :D
@muhammadsyaugi783
@muhammadsyaugi783 12 дней назад
thanks man its very helpul for me
@overrevvv
@overrevvv 5 месяцев назад
Thank you so much for this amazing video! Btw I have one question regarding the font or extension you're using in your VS code setup, what exactly is responsible to create different font in some of the code for example at 4:26 in the function validateUser the parameter authPayloadDto have different font.
@ansonthedev
@ansonthedev 5 месяцев назад
That's just how VS code often does it, I believe. The fonts are different because one of the names is the method name, and the other is a method argument. The font name is Operator Mono and the theme is Horizon.
@lifeInGod2K
@lifeInGod2K 5 месяцев назад
Well explained, thank you!!
@ansonthedev
@ansonthedev 5 месяцев назад
You're welcome
@varunvunnikrishnan4054
@varunvunnikrishnan4054 5 месяцев назад
I can see the authservice class highlighted with red color due to error. Then, How are you getting the result ?
@prashlovessamosa
@prashlovessamosa 5 месяцев назад
Thanks Anson.
@ernestsdane3510
@ernestsdane3510 5 месяцев назад
This is great! I would love to see session auth implementation and websocket securing
@newquery685
@newquery685 5 месяцев назад
I think he made one already
@ismaeltinta6118
@ismaeltinta6118 4 месяца назад
link please? @@newquery685
@asadmehboob1300
@asadmehboob1300 5 месяцев назад
Great video....can bun increase Nestjs speed?
@chairilashar7022
@chairilashar7022 5 месяцев назад
Hello sir, can i request a future playlist for nest with redis?
@BartSimpson-pm3bs
@BartSimpson-pm3bs 3 месяца назад
in thunder client, you can alse add the jwt in the auth section, no need in the headers section
@cryptotechita4889
@cryptotechita4889 2 месяца назад
Legend
@deepikamateti17
@deepikamateti17 5 месяцев назад
How is the guard and strategy mapping happening is it because of the value in Authguard and it checks for that value strategy file name or is it because of passport import? also can I have 2 local strategies?
@ansonthedev
@ansonthedev 5 месяцев назад
The guard invokes the Strategy, basically the string argument you pass into the AuthGuard() decorator lets NestJS know which Strategy to call. For example, if you use Google, you'd pass "google" into the AuthGuard decorator like this: AuthGuard("google"). Then NestJS will check if there is a Google Strategy registered, if not it will throw a "strategy not found" error or something similar indicating the strategy does not exist. Not sure what you mean by "2 local strategies", but you can have the standard way of authenticating, using username/email and password. If using JWT, you'd need JWT and Local strategies. Anything else would be 3rd party such as OAuth2 using something like Google or Discord to authenticate.
@deepikamateti17
@deepikamateti17 5 месяцев назад
@@ansonthedev Got it thanks!
@gregscolumn
@gregscolumn 5 месяцев назад
Thanks for uploading this video. Could you please make one for adding and getting user specific data. Like user can only see the data they add to the server. Been struggling with that lately. Thank ❤
@TM-jb8bw
@TM-jb8bw 4 месяца назад
Awesome 🎉
@ansonthedev
@ansonthedev 4 месяца назад
Thank you!
@igmtink
@igmtink 2 месяца назад
sir anson it's seems like refresh token is missing? how we can implement two token? access token for short lifespan and refresh token for long lifespan that we are storing it on database
@ansonthedev
@ansonthedev 2 месяца назад
You just create a second JWT that lasts longer than the access token, and use that to "refresh" the access token.
@igmtink
@igmtink 2 месяца назад
@@ansonthedev it's the same procedure sir to create the refresh token? but on the auth.module.ts we set the "JwtModule" with expiration, how can I handle a two expiration for accessToken and refreshToken?
@ansonthedev
@ansonthedev 2 месяца назад
You can use the JwtService and call .sign() or .signAsync() and manually set the expiresIn property. That will override the setting you configured in JwtModule. e.g: this.jwtService.sign(user, { secret: '123', expiresIn: '123' })
@pratikmande
@pratikmande 3 месяца назад
i just want to know how to throw an HttpException instead of return null,
@thetrungphaninh8274
@thetrungphaninh8274 3 месяца назад
I follow your video but I encountered the problem "property 'user' doesn't exists on type 'Request'" when I call req.user. Can you help me fix this bug.
@ansonthedev
@ansonthedev 3 месяца назад
You need to make sure you have both Local and Auth guard. Check the code repository here and make sure you didn't miss anything: github.com/stuyy/nestjs-passport-jwt-example/
@gregscolumn
@gregscolumn 3 месяца назад
Thanks for this, but I am having an error here, I am using email instead of username, when I test the login endpoint in and pass the correct email and password I still get the Unauthorised error coming from the local strategy, please is there any solution to this or is it that we can only use username to authenticate? Thanks once again
@ansonthedev
@ansonthedev 3 месяца назад
In the LocalStrategy file, where you are calling super(), you want to pass options and set "usernameField" to the field name. So for example, if the field name is "email" then the options would look like this: { usernameField: 'email' }
@gregscolumn
@gregscolumn 3 месяца назад
@@ansonthedev okay thanks, let me try it
@gregscolumn
@gregscolumn 3 месяца назад
hey, so I got to the jwt guard part, and I keep getting the same Unauthorized message even after using the correct JWT Code, since I am using email instead of username? is there anything I need to pass super() ? Thanks
@jaydraws2019
@jaydraws2019 Месяц назад
I got the same problem. Decided to followup on another tutorial. After wasting hours, I've moved on to another tutorial lol.
@newquery685
@newquery685 5 месяцев назад
Could you make one about the refresh token
@SatryaNouvanda
@SatryaNouvanda Месяц назад
Please make one.
@geraldnwanze989
@geraldnwanze989 3 месяца назад
okay, so i keep getting unauthorized when using the local guard. i decided to check and found out that the local strategy was not hit during the request
@ansonthedev
@ansonthedev 3 месяца назад
Make sure the strategy file is being registered by passing it as a provider in the module
@geraldnwanze989
@geraldnwanze989 3 месяца назад
okay, i figured out the issue. had to modify the request in the local auth guard to match columns i use for validation
@wallelignworkie8749
@wallelignworkie8749 18 дней назад
the DB is?
@SashaYursa
@SashaYursa 4 месяца назад
so difficult for me, too much steps to keep in mind, maybe i shoud rewatch video
@dr-Jonas-Birch
@dr-Jonas-Birch 5 месяцев назад
Good info but this video doesn't have that "Anson soul" that we have known and loved, and which makes your videos very special. I think you are too conscious about not talking too fast. And don't cut, it makes you lose the rhytm. Rest is great though. JB
@user-tg5qw2wv5n
@user-tg5qw2wv5n 18 дней назад
Thank you for your video, but I referred to the official documents and saw similar writing methods. I think the order of decorators should be that post should be executed first. It would be more intuitive, but in theory, calling rest will execute all the decorators of function. , for your reference @UseGuards(LocalAuthGuard) @Post('login') login(@Req() req: Request) { return req.user; }
@JacobSucksAtCode
@JacobSucksAtCode 3 месяца назад
One quick hack for next time: nest g resource auth --no-spec ❤ Fire video overall bro!
Далее
How to Dockerize NestJS with MySQL
35:46
Просмотров 8 тыс.
когда повзрослела // EVA mash
00:40
Просмотров 1,4 млн
Monster shops mini mart 👻🛒 #shorts
00:49
Просмотров 12 млн
I Played Fabiano Caruana
12:03
Просмотров 110 тыс.
The ARCH LINUX Experience
34:30
Просмотров 58 тыс.
The ultimate NestJS Authentication guide
31:00
Express JS #13 - Sessions Pt. 1
16:30
Просмотров 6 тыс.
JWT Authentication Tutorial - Node.js
27:36
Просмотров 1 млн
Decouple your NestJS code with this technique!
11:37
Просмотров 32 тыс.
Аутентификация в NestJS
3:56:40
Просмотров 19 тыс.
Обзор на 10 дешевых мангалов
0:57
Как вам?)) #нескучныйучитель
0:12