The login works well, but when i refresh the page it logouts.
I added in Auth0 Configuration: http://localhost:4200 on Allowed Web Origins
export class AppComponent implements OnInit {
constructor(public auth: AuthService) {
auth.handleAuthentication();
}
ngOnInit() {
if (this.auth.isAuthenticated()) {
this.auth.renewTokens();
}
}
}
It does not show any error message. I´ve put console.log in the functions of renew token or logout and it does not enter.
public renewTokens(): void {
console.log("adios3");
this.auth0.checkSession({}, (err, authResult) => {
if (authResult && authResult.accessToken && authResult.idToken) {
this.localLogin(authResult);
} else if (err) {
alert(`Could not get a new token (${err.error}: ${err.error_description}).`);
this.logout();
}
});
}
public logout(): void {
// Remove tokens and expiry time
console.log("adios1");
this._accessToken = '';
this._idToken = '';
this._expiresAt = 0;
this.auth0.logout({
returnTo: window.location.origin
});
}
public isAuthenticated(): boolean {
console.log("adios4");
// Check whether the current time is past the
// access token's expiry time
return this._accessToken && Date.now() < this._expiresAt;
}