diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index d4838e24289ac083a5f9e8a783f997624cdc4a58..5dce23f83ad8bb2d1a18cc0350812cc6f5440030 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -26,8 +26,7 @@ const routes: Routes = [ { path: 'room/:roomId', component: RoomComponent, - canActivate: [AuthenticationGuard], - data: { roles: [UserRole.PARTICIPANT, UserRole.CREATOR] } + canActivate: [AuthenticationGuard] }, { path: '**', component: PageNotFoundComponent } ]; diff --git a/src/app/authentication.guard.ts b/src/app/authentication.guard.ts index 5e0393aab1dae9a0233e4c362ad73c012611443b..3883037a46bfe57fd992fdba30d81389f61c636e 100644 --- a/src/app/authentication.guard.ts +++ b/src/app/authentication.guard.ts @@ -18,8 +18,13 @@ export class AuthenticationGuard implements CanActivate { canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> { return this.authenticationService.getUser().map(user => { + // Get roles having access to this route + // undefined if every logged in user should have access regardless of its role const requiredRoles = next.data['roles'] as Array<UserRole>; - if (user && requiredRoles.includes(user.role)) { + // Allow access when user is logged in AND + // the route doesn't require a specific role OR + // the user's role is one of the required roles + if (user && (!requiredRoles || requiredRoles.includes(user.role))) { return true; } this.notificationService.show(`You're not authorized to view this page.`);