diff --git a/src/app/app.component.html b/src/app/app.component.html index 7e4c070..6a164d6 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1,2 +1,2 @@ - + diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts deleted file mode 100644 index bc98df0..0000000 --- a/src/app/app.component.spec.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { TestBed } from '@angular/core/testing'; -import { AppComponent } from './app.component'; - -describe('AppComponent', () => { - beforeEach(async () => { - await TestBed.configureTestingModule({ - imports: [AppComponent], - }).compileComponents(); - }); - - it('should create the app', () => { - const fixture = TestBed.createComponent(AppComponent); - const app = fixture.componentInstance; - expect(app).toBeTruthy(); - }); - - it(`should have the 'lf10StarterNew' title`, () => { - const fixture = TestBed.createComponent(AppComponent); - const app = fixture.componentInstance; - expect(app.title).toEqual('lf10StarterNew'); - }); - - it('should render title', () => { - const fixture = TestBed.createComponent(AppComponent); - fixture.detectChanges(); - const compiled = fixture.nativeElement as HTMLElement; - expect(compiled.querySelector('h1')?.textContent).toContain('Hello, lf10StarterNew'); - }); -}); diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 1f55f42..c3fb0ad 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,11 +1,10 @@ -import { Component } from '@angular/core'; -import { CommonModule } from '@angular/common'; -import { RouterOutlet } from '@angular/router'; -import {EmployeeListComponent} from "./employee-list/employee-list.component"; +import {Component} from '@angular/core'; +import {CommonModule} from '@angular/common'; +import {RouterOutlet} from '@angular/router'; @Component({ selector: 'app-root', - imports: [CommonModule, EmployeeListComponent], + imports: [CommonModule, RouterOutlet], templateUrl: './app.component.html', styleUrl: './app.component.css' }) diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts index dc39edb..c007ee6 100644 --- a/src/app/app.routes.ts +++ b/src/app/app.routes.ts @@ -1,3 +1,10 @@ -import { Routes } from '@angular/router'; +import {Routes} from '@angular/router'; +import {EmployeeListComponent} from "./employee-list/employee-list.component"; +import {LoginComponent} from "./login/login.component"; +import {AuthGuardService} from "./auth-guard.service"; -export const routes: Routes = []; +export const routes: Routes = [ + {path: 'login', component: LoginComponent}, + {path: '', component: EmployeeListComponent, canActivate: [AuthGuardService]}, + {path: '**', redirectTo: ''} +]; diff --git a/src/app/auth-guard.service.ts b/src/app/auth-guard.service.ts new file mode 100644 index 0000000..2d97980 --- /dev/null +++ b/src/app/auth-guard.service.ts @@ -0,0 +1,20 @@ +import {Injectable} from '@angular/core'; +import {AuthService} from "./services/auth.service"; +import {Router} from "@angular/router"; + +@Injectable({ + providedIn: 'root' +}) +export class AuthGuardService { + constructor(public auth: AuthService, public router: Router) { + } + + canActivate(): boolean { + if (!this.auth.isAuthenticated()) { + this.router.navigate(['login']); + + return false; + } + return true; + } +} diff --git a/src/app/employee-list/employee-list.component.spec.ts b/src/app/employee-list/employee-list.component.spec.ts deleted file mode 100644 index 081f497..0000000 --- a/src/app/employee-list/employee-list.component.spec.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; - -import { EmployeeListComponent } from './employee-list.component'; - -describe('EmployeeListComponent', () => { - let component: EmployeeListComponent; - let fixture: ComponentFixture; - - beforeEach(async () => { - await TestBed.configureTestingModule({ - imports: [EmployeeListComponent] - }) - .compileComponents(); - - fixture = TestBed.createComponent(EmployeeListComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/src/app/login/login.component.css b/src/app/login/login.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/login/login.component.html b/src/app/login/login.component.html new file mode 100644 index 0000000..147cfc4 --- /dev/null +++ b/src/app/login/login.component.html @@ -0,0 +1 @@ +

login works!

diff --git a/src/app/login/login.component.ts b/src/app/login/login.component.ts new file mode 100644 index 0000000..b3f2e24 --- /dev/null +++ b/src/app/login/login.component.ts @@ -0,0 +1,11 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'app-login', + imports: [], + templateUrl: './login.component.html', + styleUrl: './login.component.css' +}) +export class LoginComponent { + +} diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts new file mode 100644 index 0000000..55b1d26 --- /dev/null +++ b/src/app/services/auth.service.ts @@ -0,0 +1,10 @@ +import {Injectable} from '@angular/core'; + +@Injectable({ + providedIn: 'root' +}) +export class AuthService { + public isAuthenticated(): boolean { + return false; + } +}