Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. principal.isAuthenticated()
  2.  
  3. principal.hasAnyAuthority(['ROLE_ADMIN'])
  4.  
  5. ngAfterContentChecked() {
  6. console.log('ngAfterContentChecked');
  7. console.log(this.principal.isAuthenticated());
  8. }
  9.  
  10. <div>{{isAuthenticated()}}</div>
  11.  
  12. if(!this.isAuthenticated()) {
  13. this.model.push({ label: 'Sign in', icon: 'fa fa-fw fa-sign-in', command: (onclick)=> {this.login()} });
  14. } else {
  15. this.model.push({ label: 'Sign out', icon: 'fa fa-fw fa-sign-in', command: (onclick)=> {this.logout()} });
  16. }
  17.  
  18. this.principal.identity().then((account) => {
  19. this.currentAccount = account;
  20. });
  21.  
  22. core.js?593e:1440 ERROR TypeError: _this.connectedPromise is not a function
  23. at eval (tracker.service.ts?aa77:50)
  24. at eval (webstomp.js?afe9:292)
  25. at Array.forEach (<anonymous>)
  26. at SockJS.ws.onmessage (webstomp.js?afe9:284)
  27. at SockJS.EventTarget.dispatchEvent (eventtarget.js?d62b:51)
  28. at eval (main.js?8e93:274)
  29. at Array.forEach (<anonymous>)
  30. at SockJS._transportMessage (main.js?8e93:272)
  31. at WebSocketTransport.EventEmitter.emit (emitter.js?a8c1:50)
  32. at WebSocketTransport.ws.onmessage [as __zone_symbol__ON_PROPERTYmessage] (websocket.js?a354:35)
  33. defaultErrorLogger @ core.js?593e:1440
  34. ErrorHandler.handleError @ core.js?593e:1501
  35. next @ core.js?593e:5481
  36. schedulerFn @ core.js?593e:4319
  37. SafeSubscriber.__tryOrUnsub @ Subscriber.js?3959:240
  38. SafeSubscriber.next @ Subscriber.js?3959:187
  39. Subscriber._next @ Subscriber.js?3959:128
  40. Subscriber.next @ Subscriber.js?3959:92
  41. Subject.next @ Subject.js?8398:56
  42. EventEmitter.emit @ core.js?593e:4299
  43. (anonymous) @ core.js?593e:4755
  44. ZoneDelegate.invoke @ zone.js?6524:388
  45. Zone.run @ zone.js?6524:138
  46. NgZone.runOutsideAngular @ core.js?593e:4681
  47. onHandleError @ core.js?593e:4755
  48. ZoneDelegate.handleError @ zone.js?6524:392
  49. Zone.runTask @ zone.js?6524:191
  50. ZoneTask.invokeTask @ zone.js?6524:495
  51. invokeTask @ zone.js?6524:1536
  52. globalZoneAwareCallback @ zone.js?6524:1562
  53.  
  54. ngOnInit() {
  55. setTimeout(() => {
  56. this.loadMenu();
  57. }, 0);
  58. }
  59.  
  60. ngOnInit() {
  61.  
  62. /**
  63. * This will load the menu, but only show items that do not require login
  64. * because the principal is not valued yet.
  65. */
  66. this.loadMenu();
  67.  
  68. /**
  69. * This interval will run until the user is authenticated and then will reload the menu and clear the interval.
  70. */
  71. this.intervalId = setInterval(() => {
  72. if(this.isAuthenticated()) {
  73. this.loadMenu();
  74. clearInterval(this.intervalId);
  75. }
  76. }, 100);
  77. }
  78.  
  79. ngOnInit() {
  80. this.registerAuthenticationSuccess();
  81. }
  82.  
  83.  
  84. registerAuthenticationSuccess() {
  85. this.eventManager.subscribe('authenticationSuccess', (message) => {
  86. this.getAccount();
  87. });
  88. }
  89.  
  90.  
  91. getAccount() {
  92. this.principal.identity().then((account) => {
  93. this.account = account;
  94. });
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement