I am having an issue with my app.component where the user's email is not showing in the top menu immediately after logging in and being redirected to the data list page. The email only appears after I reload the page.
What I need is for the email to display right after the user logs in and is redirected to the data list page.
Below is the code snippet from app.component:
export class AppComponent implements OnInit{
title = 'app works!';
userEmail: any;
constructor(private authService: AuthService, private router: Router) { }
ngOnInit() {
this.userEmail = this.authService.getUser().name;
console.log(this.userEmail);
}
}
And here is a snippet from the login component:
onLogin(){
const user ={
email: this.email,
password: this.password
}
this.authService.loginUser(user).subscribe((data)=>{
if(data.success){
this.authService.userData(data.token, data.user);
this.flashMessage.show('You are logged in.', {cssClass: 'alert-success'});
this.router.navigate(['/']);
}else{
console.log('user didn\'t logged in');
this.flashMessage.show('You are not logged in. Wrong email or password.', {cssClass: 'alert-danger', timeout: 2000})
this.router.navigate(['/login']);
}
});
}