Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. export class AppComponent implements OnInit {
  2.  
  3.  
  4. constructor(public auth: AuthService) {
  5. auth.handleAuthentication();
  6. }
  7.  
  8. ngOnInit() {
  9. if (this.auth.isAuthenticated()) {
  10. this.auth.renewTokens();
  11. }
  12. }
  13.  
  14. }
  15.  
  16. public renewTokens(): void {
  17. console.log("adios3");
  18. this.auth0.checkSession({}, (err, authResult) => {
  19. if (authResult && authResult.accessToken && authResult.idToken) {
  20. this.localLogin(authResult);
  21. } else if (err) {
  22. alert(`Could not get a new token (${err.error}: ${err.error_description}).`);
  23. this.logout();
  24. }
  25. });
  26. }
  27.  
  28. public logout(): void {
  29. // Remove tokens and expiry time
  30. console.log("adios1");
  31. this._accessToken = '';
  32. this._idToken = '';
  33. this._expiresAt = 0;
  34.  
  35. this.auth0.logout({
  36. returnTo: window.location.origin
  37. });
  38. }
  39.  
  40. public isAuthenticated(): boolean {
  41. console.log("adios4");
  42. // Check whether the current time is past the
  43. // access token's expiry time
  44. return this._accessToken && Date.now() < this._expiresAt;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement