Skip to content

Commit

Permalink
fix: use strict false when getting guard providers
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcdo29 committed Mar 7, 2024
1 parent 65e4a3d commit 08ff410
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 6 additions & 4 deletions packages/or-guard/src/lib/and.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@ interface AndGuardOptions {

export function AndGuard(
guards: Array<Type<CanActivate> | InjectionToken>,
orGuardOptions?: AndGuardOptions
andGuardOptions?: AndGuardOptions
) {
class AndMixinGuard implements CanActivate {
private guards: CanActivate[] = [];
constructor(@Inject(ModuleRef) private readonly modRef: ModuleRef) {}
canActivate(context: ExecutionContext): Observable<boolean> {
this.guards = guards.map((guard) => this.modRef.get(guard));
this.guards = guards.map((guard) =>
this.modRef.get(guard, { strict: false })
);
const canActivateReturns: Array<() => Observable<boolean>> =
this.guards.map((guard) => () => this.deferGuard(guard, context));
const mapOperator = orGuardOptions?.sequential ? concatMap : mergeMap;
const mapOperator = andGuardOptions?.sequential ? concatMap : mergeMap;
return from(canActivateReturns).pipe(
mapOperator((obs) => {
return obs().pipe(this.handleError());
Expand Down Expand Up @@ -61,7 +63,7 @@ export function AndGuard(

private handleError(): OperatorFunction<boolean, boolean> {
return catchError((err) => {
if (orGuardOptions?.throwOnFirstError) {
if (andGuardOptions?.throwOnFirstError) {
return throwError(() => err);
}
return of(false);
Expand Down
4 changes: 3 additions & 1 deletion packages/or-guard/src/lib/or.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export function OrGuard(
private guards: CanActivate[] = [];
constructor(@Inject(ModuleRef) private readonly modRef: ModuleRef) {}
canActivate(context: ExecutionContext): Observable<boolean> {
this.guards = guards.map((guard) => this.modRef.get(guard));
this.guards = guards.map((guard) =>
this.modRef.get(guard, { strict: false })
);
const canActivateReturns: Array<Observable<boolean>> = this.guards.map(
(guard) => this.deferGuard(guard, context)
);
Expand Down

0 comments on commit 08ff410

Please sign in to comment.