I have been creating a web application with Angular2 and Firebase,
first I check if the user is authenticated or not, if user is authenticated, he will be redirect to a page that contains the list of groups otherwise he will be redirect to a login page.
The problem is that the menu and the header are always visible.
I want the menu and the header of the application will not be displayed when user redirect to login page.
how I can do this.
app.component.ts
constructor(public af: AngularFire,private router:Router){
this.af.auth.subscribe(auth => {
if(auth) {
this.userconnected = auth;
}
}
app.component.html
<app-appheader *ngIf="userconnected" [userconnected]="userconnected"></app-appheader>
<app-appmenu *ngIf="userconnected" [userconnected]="userconnected" data-spy="affix"></app-appmenu>
<div class="content-wrapper">
<section class="content">
<div class="row">
<router-outlet></router-outlet>
</div>
</section>
</div>
<app-appfooter></app-appfooter>
app.routes.ts
{ path: 'groups', component: ListgroupsComponent, canActivate: [AuthGuard] },
{ path: '', redirectTo: 'groups', pathMatch: 'full' },
{ path: 'login', component: LoginComponent },
groups.component.ts
ngOnInit() {
console.log("ngOnInit list surveu");
this.af.auth.subscribe(auth => {
if(auth) {
this.name = auth;
this.ifInfoUser(this.name.auth.uid)
}
});
}
ifInfoUser(idUser):boolean{
console.log('BeginifInfoUser');
const user = this.af.database.object('/users/'+idUser);
user.subscribe(data => {
console.log("data");
if(data.uid!=null){
this.existUser=true;
this.router.navigate(['/groups']);
}else{
this.existUser=false;
this.router.navigate(['/login']);
}
});
return this.existUser;
}
Thanks in advance.