WIP:Login-Umleitung
authorKai Moritz <kai@juplo.de>
Sun, 7 Sep 2025 00:26:33 +0000 (02:26 +0200)
committerKai Moritz <kai@juplo.de>
Sun, 7 Sep 2025 00:26:33 +0000 (02:26 +0200)
src/app/app.component.ts
src/app/services/auth.service.spec.ts [new file with mode: 0644]
src/app/services/auth.service.ts [new file with mode: 0644]

index 61a67e8..1ab92ed 100644 (file)
@@ -1,5 +1,6 @@
 import { Component } from '@angular/core';
 import { RouterOutlet } from '@angular/router';
+import { AuthService } from './services/auth.service';
 
 @Component({
   selector: 'app-root',
@@ -9,4 +10,11 @@ import { RouterOutlet } from '@angular/router';
 })
 export class AppComponent {
   title = 'stored-login';
+
+  constructor(private authService: AuthService) {}
+
+  ngOnInit(): void
+  {
+    this.authService.assertUserIsKnown();
+  }
 }
diff --git a/src/app/services/auth.service.spec.ts b/src/app/services/auth.service.spec.ts
new file mode 100644 (file)
index 0000000..f1251ca
--- /dev/null
@@ -0,0 +1,16 @@
+import { TestBed } from '@angular/core/testing';
+
+import { AuthService } from './auth.service';
+
+describe('AuthService', () => {
+  let service: AuthService;
+
+  beforeEach(() => {
+    TestBed.configureTestingModule({});
+    service = TestBed.inject(AuthService);
+  });
+
+  it('should be created', () => {
+    expect(service).toBeTruthy();
+  });
+});
diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts
new file mode 100644 (file)
index 0000000..b0c594a
--- /dev/null
@@ -0,0 +1,21 @@
+import { Injectable } from '@angular/core';
+import { Router } from "@angular/router";
+
+@Injectable({
+  providedIn: 'root'
+})
+export class AuthService {
+  private username : string|undefined;
+
+  constructor(private router : Router) { }
+
+  login(username : string, password : string) {
+    this.username = username;
+  }
+
+  assertUserIsKnown(): void {
+    if(!this.username) {
+      this.router.navigate(['login']);
+    }
+  }
+}