diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 2edeccf..e9146c7 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -41,17 +41,10 @@ export class AppComponent { } ngOnInit() { - console.log(this.isLoggedIn); - if (this.isLoggedIn === undefined) { this.router.navigate(['/login']); } else { - this.getUserIdInLocalStorage(); this.router.navigate(['/summary']); } } - - getUserIdInLocalStorage() { - localStorage.setItem('currentUser', JSON.stringify('5EX7gnwPPGEDbN186Rdw')); - } } diff --git a/src/app/components/login/login.component.html b/src/app/components/login/login.component.html index 572489a..c3e4e45 100644 --- a/src/app/components/login/login.component.html +++ b/src/app/components/login/login.component.html @@ -71,6 +71,7 @@ [class]="'btn-guest-login'" [type]="'button'" [value]="'Guest Log in'" + (click)="guestLogin()" > diff --git a/src/app/components/login/login.component.ts b/src/app/components/login/login.component.ts index dfbbb99..4e27b9f 100644 --- a/src/app/components/login/login.component.ts +++ b/src/app/components/login/login.component.ts @@ -2,6 +2,8 @@ import { CommonModule } from '@angular/common'; import { Component } from '@angular/core'; import { FormsModule, NgForm } from '@angular/forms'; import { FormBtnComponent } from '../../shared/components/buttons/form-btn/form-btn.component'; +import { FirebaseService } from '../../services/firebase.service'; +import { Router } from '@angular/router'; @Component({ selector: 'app-login', @@ -16,8 +18,22 @@ export class LoginComponent { password: '', }; + constructor( + private firebaseService: FirebaseService, + private router: Router + ) {} + onSubmit(ngForm: NgForm) { if (ngForm.submitted && ngForm.form.valid) { } } + + guestLogin() { + this.getUserIdInLocalStorage(); + window.location.reload(); + } + + getUserIdInLocalStorage() { + localStorage.setItem('currentUser', JSON.stringify('5EX7gnwPPGEDbN186Rdw')); + } } diff --git a/src/app/services/firebase.service.ts b/src/app/services/firebase.service.ts index 9dbb8f1..0bf4201 100644 --- a/src/app/services/firebase.service.ts +++ b/src/app/services/firebase.service.ts @@ -22,7 +22,6 @@ export class FirebaseService implements OnDestroy { allTasks: Task[] = []; filteredTasks: Task[] = []; allUsers: User[] = []; - isUserLogin: boolean = false; unsubTask; unsubUser; diff --git a/src/app/services/shared.service.ts b/src/app/services/shared.service.ts index a3bbfa0..2466a68 100644 --- a/src/app/services/shared.service.ts +++ b/src/app/services/shared.service.ts @@ -36,4 +36,15 @@ export class SharedService { cleanup() { this.removeResizeListener(); } + + // LOGOUT + + logout() { + this.deleteUserIdInLocalStorage(); + window.location.reload(); + } + + deleteUserIdInLocalStorage() { + localStorage.removeItem('currentUser'); + } } diff --git a/src/app/shared/components/navbar/navbar.component.html b/src/app/shared/components/navbar/navbar.component.html index 8ac9921..3e7579f 100644 --- a/src/app/shared/components/navbar/navbar.component.html +++ b/src/app/shared/components/navbar/navbar.component.html @@ -18,7 +18,7 @@ > {{ "navbar.legalNotice" | translate }} -
{{ "sidebar.legalNotice" | translate }}
-
{{ "sidebar.logout" | translate }}
+
{{ "sidebar.logout" | translate }}
diff --git a/src/app/shared/components/sidebar/sidebar.component.ts b/src/app/shared/components/sidebar/sidebar.component.ts index 5759194..8032efd 100644 --- a/src/app/shared/components/sidebar/sidebar.component.ts +++ b/src/app/shared/components/sidebar/sidebar.component.ts @@ -3,6 +3,7 @@ import { Component, OnInit } from '@angular/core'; import { NavigationEnd, Router, RouterModule } from '@angular/router'; import { TranslateModule } from '@ngx-translate/core'; import { LanguageService } from '../../../services/language.service'; +import { SharedService } from '../../../services/shared.service'; @Component({ selector: 'app-sidebar', @@ -16,13 +17,18 @@ export class SidebarComponent implements OnInit { constructor( private router: Router, - public languageService: LanguageService + public languageService: LanguageService, + private sharedService: SharedService ) {} ngOnInit(): void { this.getCurrentPath(); } + logout() { + this.sharedService.logout(); + } + getCurrentPath() { this.router.events.subscribe((event) => { if (event instanceof NavigationEnd) {