Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK-1931] Add support for canActivateChild and canLoad in AuthGuard #45

Merged
merged 11 commits into from
Sep 14, 2020

Conversation

stevehobbsdev
Copy link
Contributor

@stevehobbsdev stevehobbsdev commented Sep 8, 2020

This PR adds support for two other Guard interfaces: CanActivateChild and
CanLoad

  • canActivateChild is used on a route definition that contains child routes, to
    determine whether any of those child routes can be accessed
  • canLoad is used for lazy-loaded modules to determine whether the module
    should be loaded or not

The playground has been updated with some new links that demonstrate these
scenarios. For canLoad, observe the network trace while authenticated to
see that the JS assets for that module are only loaded when the route is
accessed. When unauthenticated, clicking the link does nothing as the module
should not be loaded. In the real world, canActivate may also be used on
this route to auto-login if it is accessed, but I wanted to test only the
loading part here.

Additionally, canActivateChild necessitates two new components and routes
being added to the playground: /child, and /child/nested. The former should
be accessible anonymously, while the latter (a child route) requires a login
and will auto-login when accessed.

Unit tests available for the new AuthGuard functionality and E2E tests have
been defined to cover the behaviour on the playground.

Note: This PR also updates SPA SDK to 1.12.0. More dependency updates coming in a future PR.

@stevehobbsdev stevehobbsdev added CH: Added PR is adding feature or functionality dependencies One or more dependencies are being bumped enhancement An enhancement or improvement to the SDK that could not be otherwise categorized as a new feature review:medium Medium review labels Sep 8, 2020
projects/auth0-angular/src/lib/auth.guard.ts Show resolved Hide resolved
projects/playground/src/app/app-routing.module.ts Outdated Show resolved Hide resolved
@Component({
selector: 'app-lazy-module',
templateUrl: './lazy-module.component.html',
styleUrls: ['./lazy-module.component.css'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the others inline the template and remove the styles (empty array). This one looks like the auto-generated one. Let's keep one style on all of them, and remove unnecessary files (e.g. styles, template, etc)

@stevehobbsdev stevehobbsdev merged commit 27a885d into master Sep 14, 2020
@stevehobbsdev stevehobbsdev deleted the add/auth-guards branch September 14, 2020 13:27
@stevehobbsdev stevehobbsdev added this to the v1.0.0 milestone Sep 16, 2020
@stevehobbsdev stevehobbsdev mentioned this pull request Sep 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CH: Added PR is adding feature or functionality dependencies One or more dependencies are being bumped enhancement An enhancement or improvement to the SDK that could not be otherwise categorized as a new feature review:medium Medium review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants