Unordered async guards
This commit is contained in:
parent
85c6d91b2e
commit
a8b5cfce14
@ -86,3 +86,23 @@ export function orderedAsyncGuards(guards: Array<AsyncGuard>): CanActivateFn {
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export function unorderedAsyncGuards(guards: Array<AsyncGuard>): CanActivateFn {
|
||||
return async (route, state) => {
|
||||
const injector = inject(Injector);
|
||||
const loadingService = inject(LoadingService);
|
||||
|
||||
loadingService.start();
|
||||
|
||||
try {
|
||||
const result = await Promise.all(guards.map(guard => runInInjectionContext(injector, () => guard(route, state))));
|
||||
loadingService.stop();
|
||||
return result.every(Boolean);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
loadingService.stop();
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user