diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index f4eae8e..644c2ab 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -11,7 +11,8 @@ import { AdminPageComponent } from './pages/admin-page/admin-page.component'; import { AuthGuard } from './services/auth.guard'; const routes: Routes = [ - { path: '', redirectTo: 'home', pathMatch: 'full' }, + { path: '', redirectTo: 'signin', pathMatch: 'full' }, + {path: 'signin', component: SigninComponent}, { path: 'home', component: HomePageComponent }, { path: 'categories', component: ListCategoriesComponent }, { path: 'favoris', component: FavorisUserComponent }, @@ -19,7 +20,6 @@ const routes: Routes = [ { path: 'Deconnexion', redirectTo: 'home'}, {path: 'restaurants', canActivate: [AuthGuard], component: RestoPageComponent}, {path: 'page-not-found',component: PageNotFoundComponent}, - {path: 'signin', component: SigninComponent}, {path: 'admin', component: AdminPageComponent}, {path: '**', redirectTo: 'page-not-found' } ]; diff --git a/src/app/app.component.html b/src/app/app.component.html index ea9fe72..6833802 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1,4 +1,6 @@ - - + + + - + diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 7d60f78..be5ed0d 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -11,12 +11,12 @@ export class AppComponent { title = 'simpleat'; dontShow: boolean = false; - constructor(private router:Router, private apiBackService : ApiBackService){ + constructor(public router:Router, private apiBackService : ApiBackService){ this.router.events.subscribe(e=>{ //console.log(e); if(e instanceof NavigationEnd){ console.log(e.url) - if (e.url == "/signin") { + if (e.url == "/") { this.dontShow = false; } else { this.dontShow = true; diff --git a/src/app/footer/footer.component.ts b/src/app/footer/footer.component.ts index c7a7ec5..8970ec8 100644 --- a/src/app/footer/footer.component.ts +++ b/src/app/footer/footer.component.ts @@ -1,4 +1,5 @@ import { Component, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; @Component({ selector: 'app-footer', @@ -7,7 +8,7 @@ import { Component, OnInit } from '@angular/core'; }) export class FooterComponent implements OnInit { - constructor() { } + constructor(public route : Router) { } ngOnInit(): void { } diff --git a/src/app/header/components/nav-bar/nav-bar.component.html b/src/app/header/components/nav-bar/nav-bar.component.html index e827353..a92274b 100644 --- a/src/app/header/components/nav-bar/nav-bar.component.html +++ b/src/app/header/components/nav-bar/nav-bar.component.html @@ -15,7 +15,7 @@ Categories Filtres Mes favoris - Deconnexion + Deconnexion diff --git a/src/app/header/components/nav-bar/nav-bar.component.ts b/src/app/header/components/nav-bar/nav-bar.component.ts index 6082d5b..fc81ce2 100644 --- a/src/app/header/components/nav-bar/nav-bar.component.ts +++ b/src/app/header/components/nav-bar/nav-bar.component.ts @@ -1,4 +1,7 @@ import { Component, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; +import { TokenService } from 'src/app/services/token.service'; +import { environment } from 'src/environments/environment'; @Component({ selector: 'app-nav-bar', @@ -6,10 +9,17 @@ import { Component, OnInit } from '@angular/core'; styleUrls: ['./nav-bar.component.scss'] }) export class NavBarComponent implements OnInit { + tokenKey = environment.tokenKey; - constructor() { } + constructor( private tokenService : TokenService, public route: Router) { } ngOnInit(): void { } + onCloseSession() : void { +this.tokenService.destroyToken(); +this.route.navigate(['signin']); + } + + } diff --git a/src/app/header/components/search-bar/search-bar.component.ts b/src/app/header/components/search-bar/search-bar.component.ts index 933beaf..3aecf5b 100644 --- a/src/app/header/components/search-bar/search-bar.component.ts +++ b/src/app/header/components/search-bar/search-bar.component.ts @@ -15,10 +15,14 @@ export class SearchBarComponent implements OnInit { restauByName: any[]; @Output() resultSearch = new EventEmitter(); + + constructor(private apiBackService: ApiBackService, private route: Router, private activatedRoute : ActivatedRoute) { + + this.listRestau = []; this.restauByName = []; } @@ -49,5 +53,7 @@ export class SearchBarComponent implements OnInit { // this.route.onSameUrlNavigation = 'reload'; this.route.navigate(['restaurants']); } + + } } diff --git a/src/app/services/token.service.ts b/src/app/services/token.service.ts index e430bd3..975f2e1 100644 --- a/src/app/services/token.service.ts +++ b/src/app/services/token.service.ts @@ -31,4 +31,9 @@ export class TokenService { return null; } } + + + public destroyToken(): void { + localStorage.removeItem(this.tokenKey); + } }