Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export class AppComponent implements OnInit {
- constructor(public auth: AuthService) {
- auth.handleAuthentication();
- }
- ngOnInit() {
- if (this.auth.isAuthenticated()) {
- this.auth.renewTokens();
- }
- }
- }
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement