feat(challengestandalone): challenge standalone

This commit is contained in:
ThomasL
2023-06-19 18:06:50 +02:00
parent bcf44956f9
commit 8f6716979e
165 changed files with 2794 additions and 22 deletions

View File

@@ -0,0 +1 @@
export * from './lib/authorized.guard';

View File

@@ -0,0 +1,23 @@
import { CanActivate, Router, UrlTree } from '@angular/router';
import { AuthorizationService } from '@angular-challenges/module-to-standalone/core/service';
import { Injectable } from '@angular/core';
import { Observable, map } from 'rxjs';
@Injectable({
providedIn: 'root',
})
export class IsAuthorizedGuard implements CanActivate {
constructor(
private authorizationService: AuthorizationService,
private router: Router
) {}
canActivate(): Observable<boolean | UrlTree> {
return this.authorizationService.isAuthorized$.pipe(
map((isAuthorized) =>
isAuthorized ? true : this.router.createUrlTree(['forbidden'])
)
);
}
}

View File

@@ -0,0 +1,8 @@
// @ts-expect-error https://thymikee.github.io/jest-preset-angular/docs/getting-started/test-environment
globalThis.ngJest = {
testEnvironmentOptions: {
errorOnUnknownElements: true,
errorOnUnknownProperties: true,
},
};
import 'jest-preset-angular/setup-jest';