diff --git a/src/angular/frontend/src/app/app.routes.ts b/src/angular/frontend/src/app/app.routes.ts index d879878..0fc999d 100644 --- a/src/angular/frontend/src/app/app.routes.ts +++ b/src/angular/frontend/src/app/app.routes.ts @@ -1,13 +1,27 @@ -import { Routes } from '@angular/router'; +import {Routes} from '@angular/router'; import {LoginComponent} from './components/login/login.component'; +import {HomeComponent} from './components/home/home.component'; +import {authGuard} from './guards/auth.guard'; export const routes: Routes = [ { + title: 'Login', path: 'login', component: LoginComponent, }, + { + path: '', + children: [ + { + title: 'Home', + path: '', + component: HomeComponent, + }, + ], + canActivate: [authGuard], + }, { path: '**', - redirectTo: 'login', + redirectTo: '', }, ]; diff --git a/src/angular/frontend/src/app/clients/gandalf/mithrandir/auth.service.ts b/src/angular/frontend/src/app/clients/gandalf/mithrandir/auth.service.ts index ae687d1..dfa1019 100644 --- a/src/angular/frontend/src/app/clients/gandalf/mithrandir/auth.service.ts +++ b/src/angular/frontend/src/app/clients/gandalf/mithrandir/auth.service.ts @@ -15,16 +15,20 @@ export class AuthService extends GandalfClient { private base = '/api/auth'; - check(): Observable { - return this.handleRequest(this.http.get(this.base + '/check')); + check$(onError?: (error: any) => void): Observable { + return this.handleRequest(this.http.get(this.base + '/check'), onError); } - login(command: ValidateCredentialsCommand, onError?: (error: any) => void): Observable { + checkAsync(onError?: (error: any) => void): Promise { + return lastValueFrom(this.check$(onError)); + } + + login$(command: ValidateCredentialsCommand, onError?: (error: any) => void): Observable { return this.handleRequest(this.http.post(this.base + '/login', command), onError); } loginAsync(command: ValidateCredentialsCommand, onError?: (error: any) => void): Promise { - return lastValueFrom(this.login(command, onError)); + return lastValueFrom(this.login$(command, onError)); } } diff --git a/src/angular/frontend/src/app/components/login/login.component.spec.ts b/src/angular/frontend/src/app/components/login/login.component.spec.ts deleted file mode 100644 index 18f3685..0000000 --- a/src/angular/frontend/src/app/components/login/login.component.spec.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { ComponentFixture, TestBed } from '@angular/core/testing'; - -import { LoginComponent } from './login.component'; - -describe('LoginComponent', () => { - let component: LoginComponent; - let fixture: ComponentFixture; - - beforeEach(async () => { - await TestBed.configureTestingModule({ - imports: [LoginComponent] - }) - .compileComponents(); - - fixture = TestBed.createComponent(LoginComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/src/angular/frontend/src/app/components/login/login.component.ts b/src/angular/frontend/src/app/components/login/login.component.ts index 25cd2c8..90e64d4 100644 --- a/src/angular/frontend/src/app/components/login/login.component.ts +++ b/src/angular/frontend/src/app/components/login/login.component.ts @@ -1,6 +1,7 @@ import {Component, inject, signal} from '@angular/core'; import {FormControl, FormGroup, FormsModule, FormSubmittedEvent, ReactiveFormsModule} from '@angular/forms'; import {AuthService, ValidateCredentialsCommand} from '../../clients/gandalf/mithrandir/auth.service'; +import {Router} from '@angular/router'; @Component({ selector: 'app-login', @@ -15,6 +16,7 @@ import {AuthService, ValidateCredentialsCommand} from '../../clients/gandalf/mit export class LoginComponent { private auth = inject(AuthService); + private router = inject(Router); protected loginFormGroup = new FormGroup({ usernameOrEmail: new FormControl('housemasterr'), @@ -38,5 +40,6 @@ export class LoginComponent { }); console.log('login successful'); + await this.router.navigate(['/']); } } diff --git a/src/dotnet/Suspectus.Gandalf.Mithrandir.Api/Controllers/AuthController.cs b/src/dotnet/Suspectus.Gandalf.Mithrandir.Api/Controllers/AuthController.cs index 5f37591..887031b 100644 --- a/src/dotnet/Suspectus.Gandalf.Mithrandir.Api/Controllers/AuthController.cs +++ b/src/dotnet/Suspectus.Gandalf.Mithrandir.Api/Controllers/AuthController.cs @@ -21,9 +21,10 @@ public class AuthController : ControllerBase } [HttpGet("[action]")] - public async Task Check() + public IActionResult Check() { - return Ok(true); + var sessionExists = Request.Cookies.ContainsKey("MithrandirSession"); + return Ok(sessionExists); } [HttpPost("[action]")]