0

I am using angular 14 with firebase Authentication. I want to alert the message in the home page when users are logged out.

So, does anyone have an idea for this please let me know. Thank you

auth.service.ts

  SignOut() {
    return this.afAuth.signOut().then(() => {
      localStorage.removeItem('user');

      
      this.router.navigate(['home']);


    });
  }

dashboard-menu.component.html

<a class="dropdown-item"  (click)="authService.SignOut()">Logout</a>

1 Answers1

0

You can pass a message, or any kind of data with NavigationExtras:

const navigationExtras: NavigationExtras = {state: {data: 'You are logged out'}};

this.router.navigate(['home'], navigationExtras);

In home component you can get data like the following:

private data: string;

constructor(private router: Router) { 
   const navigation = this.router.getCurrentNavigation();
   const state = navigation.extras.state as {data: string};
   alert(data)
}
JakaRanga
  • 16
  • 2