NestJS Blog API - [4] Authentication

preview_player
Показать описание
Time to finish our users endpoint by adding in jwt authentication.

------
Links



------
Social Links

Рекомендации по теме
Комментарии
Автор

just a heads up if anyone else gets the following error: Authentication strategies must have a name like I did, make sure vs code's auto import pulled Strategy from passport-jwt and not from passport. mine pulled it from passport and it drove me crazy for a couple hours to find out it pulled it from the wrong import:/ hope this helps anyone in the future

problemchild
Автор

you do realize the expiresIn is in seconds not milliseconds right ? so 3600 is actually an hour :)

problemchild
Автор

You should verify token in route /login with what is stored in database, in your variant you can enter different username and ok will be

ruslanvolovik
Автор

Thanks for the video.
One remark:
At 9:29 since you are using JWT tokens and not session, I would guess that you probably would want to use a stateless auth.
In the validate() function the JWT has already been verified. So that means that you don't have to make an extra call to the database to get the user and can just return the content of the payload defining the user like for example userId and other useful "user info" that the login put there at the creation of the token.

estranhokonsta
Автор

why make it hard for yourself and rename/move files outside of the IDE when the IDE would update the imports for you

BoKKeR
Автор

Hello! I very like your videos about nest.js! If you have enough time, please make a couple of videos with unit testing on nest.js! Thank you!

eruiluvatar
join shbcf.ru