How to wait for an API call in canActivate auth guard in angular | Angular | Learn Smart Coding

  Рет қаралды 5,971

Learn Smart Coding

Learn Smart Coding

Күн бұрын

Пікірлер: 39
@DavidAddoteye
@DavidAddoteye 2 жыл бұрын
Your video has saved me a lot of time. Thank you
@learnsmartcoding
@learnsmartcoding 2 жыл бұрын
I am glad you liked it. Don't forget to subscribe to my channel to get more videos!
@petarcholakov9748
@petarcholakov9748 9 ай бұрын
Thank you for this video. I struggled with this issue for couple of hours, but it is now resolved. Thanks!
@learnsmartcoding
@learnsmartcoding 9 ай бұрын
Glad it helped!
@amirdelfan7866
@amirdelfan7866 Жыл бұрын
this might not be enough when the backend api is too slow. you might want to add a filter after the pipe to check if the current user is undefined other wise it could happen that your code concludes false negatives
@learnsmartcoding
@learnsmartcoding Жыл бұрын
Hi Amir, Thank you for taking the time to watch this video and provide your suggestions. This video is just an example of how to wait for the backend api call-in guard. Also, the route gets activated only after receiving a response from the invoked api call irrespective of how long it takes to finiah. In case of api failure, the result will be considered false, and the route will be rejected.
@echelon3410
@echelon3410 Жыл бұрын
Thank you so much for your help !
@learnsmartcoding
@learnsmartcoding Жыл бұрын
I'm glad you liked it and it was useful.
@davidc0812
@davidc0812 11 ай бұрын
thanks dude. this was helpful.
@renithkumar105
@renithkumar105 2 жыл бұрын
You saved me, this is very useful
@learnsmartcoding
@learnsmartcoding 2 жыл бұрын
Glad to hear that!
@tannynogales7080
@tannynogales7080 2 жыл бұрын
Wow, that was very useful.. Can you please explain the same with interceptors?
@learnsmartcoding
@learnsmartcoding 2 жыл бұрын
Thank you for watching the video. The concept in this video is to wait for data and check some permissions before we allow users to go to different routes. Interceptor is to intercept the outgoing request and do some action, both are two different topics. I will cover some more HTTP Interceptor videos. kzbin.info/www/bejne/fWWlaX-odrBmmtk
@dennispitadeniya2479
@dennispitadeniya2479 2 жыл бұрын
thanks for this, really helpful
@learnsmartcoding
@learnsmartcoding 2 жыл бұрын
Glad to hear it!
@ricardoalvespaula
@ricardoalvespaula 11 ай бұрын
Even using pipe, the guard do not wait for the api call here. Any ideas?
@learnsmartcoding
@learnsmartcoding 11 ай бұрын
Hi Ricardo, Thank you for trying it out. Actually, Guard will wait for an API. Please check API that you are call or any other function that you are calling is observable. Also, this is now changed to function from Angular 16+, I will provide new videos soon on this part with latest code. Happy coding!
@rezanrasoul2286
@rezanrasoul2286 Жыл бұрын
how can I resolve that if I send the jwt tooken direct from the backend as httpOnly?
@learnsmartcoding
@learnsmartcoding Жыл бұрын
Hi Rezan, Thank you for posting your question. This video is all about how you can wait for a API call to complete before a route is activated. Meaning, the response from API is required to determine whether route can be activated or not. sending jwt token on a outgoing API call is handled by http interceptor. Please explain your question little bit more to understand your requirment so that I can help answering it. Thanks, LearnSmartCoding
@rezanrasoul2286
@rezanrasoul2286 Жыл бұрын
@@learnsmartcoding Thank you for the reply. In the example, you are fetching all the user, so you are using the Map Operator, but I want to make the guard wait for the response. If the login information is correct, it will redirect it to the control panel.
@learnsmartcoding
@learnsmartcoding Жыл бұрын
Hi Rezan, I gave just an example of how to wait for an api call. Basically, in my example, the guard will wait until the api is sending a response (as per your need) once you receive the response, you can validate and decide whether to redirect to a particular route or allow it to go to the requested route. Based on your comment, I see you are trying to send credentials to an api, and checking the sent credentials are right or wrong and then put them to login screen. Is that what you are trying to do?
@rezanrasoul2286
@rezanrasoul2286 Жыл бұрын
@@learnsmartcoding Yes i solved after I tried and saw your video carefully thanks a lot, but can you make a video how can we send a file and json data together, fx. in register form, I want to send a profile picture and json data from angular material dialog in same request to the sever
@learnsmartcoding
@learnsmartcoding Жыл бұрын
Hi Rezan, I just published the video you asked for. Please take a look at the recent two videos for more details. Hope you will like it! Regards, LearnSmartCoding
@giovaneflorek4467
@giovaneflorek4467 2 жыл бұрын
valeu indianinho, salvou a family
@elgrego3849
@elgrego3849 Жыл бұрын
thanks bro
@gunasekaran1217
@gunasekaran1217 2 жыл бұрын
Hi, Awesome one. Can i get the source code ?
@learnsmartcoding
@learnsmartcoding 2 жыл бұрын
Thanks for watching. The source code details are mentioned in the description. Also, all the source code are available at github.com/learnsmartcoding
@umeshshelke725
@umeshshelke725 2 жыл бұрын
@@learnsmartcoding I am not able to find the code there . could you please share exact link ?
@learnsmartcoding
@learnsmartcoding 2 жыл бұрын
@Umesh - Thanks for letting me know about the missing code. I just updated the repo in Github. Latest code is available at github.com/learnsmartcoding/angular-beginners-course-shopping-app The specific code you are looking at is here github.com/learnsmartcoding/angular-beginners-course-shopping-app/tree/main/src/app/core/guards I would suggest to download the entire branch and explore the working feature. Please let me know if you have any questions. Thanks, Learn Smart Coding
@umeshshelke725
@umeshshelke725 2 жыл бұрын
@@learnsmartcoding brother can you please make video on session expire warning pop-up in angular and .core ?
@learnsmartcoding
@learnsmartcoding 2 жыл бұрын
@@umeshshelke725 - sure, noted. Will publish this video shortly. Are you intrested in Azure?
@triloksingh8596
@triloksingh8596 Жыл бұрын
Every time api call while create product . How to solve Every time call api issue like permission api
@learnsmartcoding
@learnsmartcoding Жыл бұрын
Hi Trilok, I would like to help you resolve your need. Please help me understand better what exactly you need or what issue you are facing.
@triloksingh8596
@triloksingh8596 Жыл бұрын
@@learnsmartcoding unit testing and state management are very confusing topics. Please make any video
CanMatch Guard in Angular 14.1 Router (2022)
17:49
Decoded Frontend
Рет қаралды 15 М.
КОНЦЕРТЫ:  2 сезон | 1 выпуск | Камызяки
46:36
ТНТ Смотри еще!
Рет қаралды 3,7 МЛН
Непосредственно Каха: сумка
0:53
К-Media
Рет қаралды 12 МЛН
Angular 14 Functional Router Guards: What They Are & How to Use Them
23:45
Code Shots With Profanis
Рет қаралды 6 М.
Learn What the Directive Composition API Is and How To Use It in Angular 15
22:42
Code Shots With Profanis
Рет қаралды 9 М.
Mastering GLOBAL Error Handling in Angular Made EASY
6:53
Learn Smart Coding
Рет қаралды 199
First look at Signals in Angular
18:43
Decoded Frontend
Рет қаралды 46 М.
Angular Guards | Angular Auth Guard | Angular Canactivate
11:27
Monsterlessons Academy
Рет қаралды 25 М.
Secure a .NET Core API with Bearer Authentication
1:06:56
Les Jackson
Рет қаралды 191 М.
Angular 19 is a BEAST of a release!
19:39
Maximilian Schwarzmüller
Рет қаралды 53 М.
КОНЦЕРТЫ:  2 сезон | 1 выпуск | Камызяки
46:36
ТНТ Смотри еще!
Рет қаралды 3,7 МЛН