diff --git a/front/app/src/app/app.component.html b/front/app/src/app/app.component.html index e64b893e..1a915b4e 100644 --- a/front/app/src/app/app.component.html +++ b/front/app/src/app/app.component.html @@ -4,8 +4,6 @@
- -
diff --git a/front/app/src/app/layout/auth/auth.component.ts b/front/app/src/app/layout/auth/auth.component.ts index 05219468..ab9e3154 100644 --- a/front/app/src/app/layout/auth/auth.component.ts +++ b/front/app/src/app/layout/auth/auth.component.ts @@ -7,7 +7,10 @@ import {NgbModal} from "@ng-bootstrap/ng-bootstrap"; @Component({ selector: 'login', template: ` - + + ` @@ -45,6 +54,8 @@ export class LoginComponent { form: FormGroup; + isAuthenticated: boolean = false + constructor(private fb:FormBuilder, private authService: AuthService, private modalService: NgbModal @@ -57,9 +68,13 @@ export class LoginComponent { this.authService.onAuthenticationRequired$.subscribe((required: boolean) => { if (required) { - this.openLoginModal() + this.openLoginModal(); } }) + this.isAuthenticated = this.authService.is_authenticated; + this.authService.onIsAuthenticated$.subscribe((isAuthenticated: boolean) => { + this.isAuthenticated = isAuthenticated; + }) } openLoginModal() { @@ -84,13 +99,21 @@ export class LoginComponent { @Component({ selector: 'logout', template: ` - + ` }) export class LogoutComponent { @Output() logoutSuccess = new EventEmitter() + isAuthenticated: boolean = false constructor(private authService: AuthService) { + this.isAuthenticated = this.authService.is_authenticated; + this.authService.onIsAuthenticated$.subscribe((isAuthenticated: boolean) => { + this.isAuthenticated = isAuthenticated + }) } logout() { diff --git a/front/app/src/app/layout/auth/auth.service.ts b/front/app/src/app/layout/auth/auth.service.ts index 0946a45d..f8c47a0e 100644 --- a/front/app/src/app/layout/auth/auth.service.ts +++ b/front/app/src/app/layout/auth/auth.service.ts @@ -18,9 +18,15 @@ export class AuthService { private authenticationRequired = new Subject(); onAuthenticationRequired$ = this.authenticationRequired.asObservable(); + is_authenticated = false; + private isAuthenticated = new Subject(); + onIsAuthenticated$ = this.isAuthenticated.asObservable(); + constructor(private http: HttpClient, private flashMessage: FlashmessagesService) { this.access_token = localStorage.getItem('authtoken') + this.is_authenticated = Boolean(this.access_token) + this.isAuthenticated.next(this.is_authenticated) } login(username:string, password:string ) { @@ -36,6 +42,8 @@ export class AuthService { localStorage.setItem('authtoken', v.access_token); this.access_token = v.access_token this.flashMessage.success('Login successful. Welcome ' + username); + this.is_authenticated = true; + this.isAuthenticated.next(this.is_authenticated) return username } )); } @@ -48,6 +56,8 @@ export class AuthService { localStorage.removeItem('authtoken'); this.access_token = null; this.flashMessage.success('Logout successful. Goodbye'); + this.is_authenticated = false; + this.isAuthenticated.next(this.is_authenticated) } )); } @@ -59,5 +69,7 @@ export class AuthService { localStorage.removeItem('authtoken'); this.access_token = null; this.authenticationRequired.next(true); + this.is_authenticated = false; + this.isAuthenticated.next(this.is_authenticated) } } \ No newline at end of file diff --git a/front/app/src/app/layout/sidenav/sidenav.component.html b/front/app/src/app/layout/sidenav/sidenav.component.html index 2567054f..8d869662 100644 --- a/front/app/src/app/layout/sidenav/sidenav.component.html +++ b/front/app/src/app/layout/sidenav/sidenav.component.html @@ -3,10 +3,14 @@ Cooper, Hillman & Toshi LLP
diff --git a/front/app/src/app/layout/sidenav/sidenav.component.ts b/front/app/src/app/layout/sidenav/sidenav.component.ts index 5b6251af..c4031bb2 100644 --- a/front/app/src/app/layout/sidenav/sidenav.component.ts +++ b/front/app/src/app/layout/sidenav/sidenav.component.ts @@ -1,6 +1,7 @@ import { Component } from "@angular/core"; import { Router } from '@angular/router'; import { IconNamesEnum } from "ngx-bootstrap-icons"; +import { AuthService } from "../auth/auth.service"; @Component({ selector: "sidenav", @@ -41,7 +42,17 @@ export class SidenavComponent { }, ] - constructor(private router: Router) {} + isAuthenticated: boolean = false + + constructor( + private router: Router, + private authService: AuthService,) { + + this.isAuthenticated = this.authService.is_authenticated; + this.authService.onIsAuthenticated$.subscribe((isAuthenticated: boolean) => { + this.isAuthenticated = isAuthenticated; + }) + } is_current_page(menu_item: any) { return this.router.url.indexOf(menu_item.link) > -1;