Skip to content Skip to sidebar Skip to footer

Angular Auth.guard No Persisten Auth

Authentication doesn't seem to persist after page has been refreshed. Whenever I login, it successfully redirects me. but, when i refreshed, accessing is not possible anymore. here

Solution 1:

Try this code

constructor(
    private router:Router,
    public fireauth:AngularFireAuth
){}

canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean | Observable<boolean> | Promise<boolean> {
    return this.fireauth.authState.map((auth) =>  {
        if(auth == null) {
          this.router.navigate(['/']);
          return false;
        } else {
          return true;
        }
      });
}

i think this.fireauth.auth.onAuthStateChanged is used in older versions


Post a Comment for "Angular Auth.guard No Persisten Auth"