My application allows access to contents based on user roles. I wrote a Router Guard for each role. Some contents allow access for role1 or role2 or role3. How should I write that canActivate declaration in the feature-routing.module.ts file? As I understand, if I write
canActivate:[Role1Guard, Role2Guard, Role3Guard]
The access will be denied if any of the guards returns false. But in my case, I should allow access if any of the guards returns true. How to do it? Many thanks in advance!
Best Answer
What we can do in this case is create a Master Guard which will trigger the application guards as per our requirement.
Checkout this answer to understand the approach.
Assuming you have gone through it above link, the approach in this case could be as simple as modifying the
data
property inRoute
class.Something like this -
And then use
operator
flag to fire all guards accordingly.I hope this helps :)