Angular Guards | Angular Auth Guard | Angular Canactivate
ฝัง
- เผยแพร่เมื่อ 29 ม.ค. 2023
- Learn Angular guards by implementing Angular auth guard. This is the most popular way to protect your pages for unathorized users with Angular canactivate method.
► CHECK MY COURSES - monsterlessons-academy.com/co...
FOLLOW ME
► TWITTER - / monster_lessons
REFERENCES
► Source code - github.com/monsterlessonsacad...
Thank you so much for this, I have been on the struggle bus.
You are so welcome!
I like your content but class-based guards (and resolvers) are deprecated from Angular 15.2. Hoped to see how you implement functional guards, but maybe that's a good topic for another video and I can imagine many people will search specifically for this from now on :)
It is planned in the nearest future
I have the same request 😂
@@MonsterlessonsAcademy tanks
Awesome, very useful!
Glad it was helpful!
Awesome, easy to understand
Glad to hear that!
damn, you made it look easy but this is hard to undertand. Thanks bro
You are welcome!
Awesome video. Could you please also provide a video about the future of angular comparing with react
Good idea. I will add it to the list of future videos.
💯
i only get currentUser value undefined in canActivate Function . const authService = inject(AuthService); export const hasRoleGuard: CanActivateFn = (route, state) => { return authService.currentUser$.pipe( ) etc ....
Hi and thanks. What about function-style guards?
You are welcome! You can for sure also usee function style guards, the difference is minimal
@@MonsterlessonsAcademy It's not that minimal actually. It turns out you don't have access to DI in the functions, as they are not in an injector scope unless you are using a standalone component. That necessitates some further complications and workarounds such as the use of EnvironmentInjector and/or some other tricks.
@@gkarapeev Thanks for the info. I will plan some videos on them then!
@@MonsterlessonsAcademy great, thank you, looking forward to seeing them. :)
What about is you want to guard from the server side?
You need to make an API call to BE then in your guard
One question: there are many react clones of popular websites tutorial on youtube, can we code a clone and add to our public github repository ? I don't want to use it for any business or sell it to somebody. I want to use it just to get job, that shows my skills
Yes sure you can but you must be able to answer questions about every single line in a project. In other case people will think that you just copied it.
Another problem that "coding a clone" by tutorial doesn't equal your code written from scratch. So it may be to polished and far from the code that you write.
@@MonsterlessonsAcademy so if i create google clone and used google logo, its not illegal to put it in my public github repo?
Oh god... It will be so embarassing when they find out you didnt create that work
deprecated canActivate
Yes exactly
canactivate is depracted...
I already made a video about new way of canactivate
th-cam.com/video/Yc93IvrouxY/w-d-xo.htmlsi=Mc_BDRHVXQIqzPw_
@@MonsterlessonsAcademy that is great! exacly what i looked for, good video thanx, maybe you should add a link to it as update in ur video ;) beacuse Functional Guards wasnt clear to me, as i looked for canactivate depracated