I'm using firebase for the signIn and signup. that is my authService look like :
token: string;
authenticated: boolean = false;
signinUser(email: string, password: string) {
firebase
.auth()
.signInWithEmailAndPassword(email, password)
.then(response => {
this.authenticated = true;
console.log('authService-->signinUser-->authenticated', this.authenticated);
//Set the a wallet using a combination of the email and the name of the network e.g. Majd@gmail.com@stschain
this.dataService.setWallet(`${email}${this.domainExtenstion}`);
this.setEmail(email);
this.router.navigate(['/dashboard']);
console.log('sinign in')
firebase
.auth()
.currentUser.getIdToken()
.then(
(token: string) => {
(this.token = token);
// localStorage.setItem('token', JSON.stringify(token));
}
);
})
.catch(error => {
console.log(error);
alert(error);
});
}
isAuthenticated() {
return this.token != null;
}
and in my authGuardService im calling canactivate methode like this :
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
if (!this.authService.authenticated) {
console.log('cant load' )
this.router.navigate(['/signin']);
}
console.log('can load' )
return this.authService.isAuthenticated();
}
}
but when i refresh the page this authenticated
value get false always.
Please, anyone, know the cause that will appreciate.