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

Add API for standalone and functional approaches #445

Merged
merged 1 commit into from
Apr 3, 2023
Merged

Conversation

frederikprijck
Copy link
Member

Description

Adds syntactic sugar to work better with standalone and functional approaches.

Note: This should only be used with Angular 15.

References

#444
#442

Testing

  • This change adds test coverage for new/changed/fixed functionality

Checklist

  • I have added documentation for new/changed functionality in this PR or in auth0.com/docs
  • All active GitHub checks for tests, formatting, and security are passing
  • The correct base branch is being used, if not the default branch

*/
export const authHttpInterceptorFn = (
req: HttpRequest<any>,
handle: (req: HttpRequest<unknown>) => Observable<HttpEvent<unknown>>
Copy link
Member Author

Choose a reason for hiding this comment

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

Because we have no access to Angular15, we can not type this as HttpHandlerFn yet.

Choose a reason for hiding this comment

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

I believe you mean HttpInterceptorFn here

Copy link
Member Author

@frederikprijck frederikprijck Apr 3, 2023

Choose a reason for hiding this comment

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

No, HttpHandlerFn. The second argument (it's called next in the Angular source code, handle in our code tho) of the interceptor is of type HttpHandlerFn, see: https://github.com/angular/angular/blob/febf29dd5197f8943e6377a8fc66a14b3a1c5973/packages/common/http/src/interceptor.ts#L90

export const authGuardFn = (
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
) => inject(AuthGuard).canActivate(route, state);
Copy link
Member Author

Choose a reason for hiding this comment

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

This only uses canActivate. However, canActivate and canActivateChild are identical implementation wise. So people can use authGuardFn for both scenarios.

Copy link
Contributor

@ewanharris ewanharris left a comment

Choose a reason for hiding this comment

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

Looks good, added a minor comment but shouldn't block merge imo

* Initialize the authentication system. Configuration can either be specified here,
* or by calling AuthClientConfig.set (perhaps from an APP_INITIALIZER factory function).
*
* Note: Should only be used as of Angular 15, and should not be added to a component's providers.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there anyway we can have this as a check in the code and throw an error?

@frederikprijck frederikprijck merged commit 4a528e8 into master Apr 3, 2023
@frederikprijck frederikprijck deleted the feat/444 branch April 3, 2023 12:59
@frederikprijck frederikprijck mentioned this pull request Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants