{"action":"created","issue":{"url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/1742","labels_url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/1742/labels{/name}","comments_url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/1742/comments","events_url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/1742/events","html_url":"https://github.com/jhipster/generator-jhipster/issues/1742","id":95674962,"number":1742,"title":"Admin bar disappears when refreshing settings page","user":{"login":"hegek87","id":1440543,"avatar_url":"https://avatars.githubusercontent.com/u/1440543?v=3","gravatar_id":"","url":"https://api.github.com/users/hegek87","html_url":"https://github.com/hegek87","followers_url":"https://api.github.com/users/hegek87/followers","following_url":"https://api.github.com/users/hegek87/following{/other_user}","gists_url":"https://api.github.com/users/hegek87/gists{/gist_id}","starred_url":"https://api.github.com/users/hegek87/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hegek87/subscriptions","organizations_url":"https://api.github.com/users/hegek87/orgs","repos_url":"https://api.github.com/users/hegek87/repos","events_url":"https://api.github.com/users/hegek87/events{/privacy}","received_events_url":"https://api.github.com/users/hegek87/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-07-17T15:06:45Z","updated_at":"2015-07-18T12:01:30Z","closed_at":null,"body":"Hey,\r\n\r\nUsing Jhipster 2.16.1 an error on the settings page was found using chrome and safari. To reproduce this, do the following: \r\n\r\n1. Log in as an admin\r\n2. Go to account -> settings\r\n3. Refresh the page\r\n\r\nYou will see that the administration bar has disappeared. \r\n\r\nI have a fix for this that I committed to a local project, but I'm interested in hearing thoughts about this fix. The issue is caused by forcing the identity to be fetched in settings.controller.js. The has-role directive used in settings.html is run before the promise is returned and after the identity is set to undefined, hence it doesn't see the user as an admin and the admin bar is hidden.\r\n\r\nMy first (this is a commit of the forked sample app https://github.com/hegek87/jhipster-sample-app/commit/5e8731dcdfe5edf4bda0276d219d38fd77981cd3 ), and preferred attempt, was to resolve the settingsAccount in the settings state. This fixes the issue when we refresh the page, however, when we go to home, then return to account -> settings we get the following error:\r\n\r\nTypeError: Cannot read property 'roles' of undefined\r\n    at Object.Principal.isInAnyRole (principal.service.js:23)\r\n    at auth.service.js:40\r\n    at processQueue (angular.js:14454)\r\n    at angular.js:14470\r\n    at Scope.$eval (angular.js:15719)\r\n    at Scope.$digest (angular.js:15530)\r\n    at Scope.$apply (angular.js:15824)\r\n    at angular.js:17580\r\n    at completeOutstandingRequest (angular.js:5370)\r\n    at angular.js:5642\r\n\r\nI believe this is caused by the root state resolve, which calls Auth.authorize before the child state 'settings' calls its resolve which assigns _identity in Principal. \r\n\r\nSo while searching for a way to delay the directive until after the promise returns I found $timeout. In https://github.com/hegek87/jhipster-sample-app/commit/3f3fb9f6268389b4c04294080e46b7da85e33bbd, I was able to fix the issue by adding a zero second timeout to the hasRole directive.\r\n\r\nIs the zero second timeout an acceptable fix? If so, I'd be happy to submit a pull request. I'm interested in hearing other solutions if you guys have any ideas."},"comment":{"url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/comments/122534848","html_url":"https://github.com/jhipster/generator-jhipster/issues/1742#issuecomment-122534848","issue_url":"https://api.github.com/repos/jhipster/generator-jhipster/issues/1742","id":122534848,"user":{"login":"atomfrede","id":203401,"avatar_url":"https://avatars.githubusercontent.com/u/203401?v=3","gravatar_id":"","url":"https://api.github.com/users/atomfrede","html_url":"https://github.com/atomfrede","followers_url":"https://api.github.com/users/atomfrede/followers","following_url":"https://api.github.com/users/atomfrede/following{/other_user}","gists_url":"https://api.github.com/users/atomfrede/gists{/gist_id}","starred_url":"https://api.github.com/users/atomfrede/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atomfrede/subscriptions","organizations_url":"https://api.github.com/users/atomfrede/orgs","repos_url":"https://api.github.com/users/atomfrede/repos","events_url":"https://api.github.com/users/atomfrede/events{/privacy}","received_events_url":"https://api.github.com/users/atomfrede/received_events","type":"User","site_admin":false},"created_at":"2015-07-18T12:01:30Z","updated_at":"2015-07-18T12:01:30Z","body":"@gzsombor I've changed the ``principal.service.js`` like this (and admin bar never disappears). Is this the correct implementation of a promise?\r\n\r\n```\r\nisInRole: function (role) {\r\n   var deferred = $q.defer();\r\n   \r\n  $q.when(\"_identity\")\r\n            .then(function() {\r\n                  if (!_authenticated || !_identity || !_identity.roles) {\r\n                       deferred.resolve(false);\r\n                  } else {\r\n                       deferred.resolve(_identity.roles.indexOf(role) !== -1);\r\n                  }\r\n           });\r\n\r\n  return deferred.promise;\r\n}\r\n```"}}