Skip to content

Commit

Permalink
Issue 217: Swap and adjust the boolean logic to be more JS-safe.
Browse files Browse the repository at this point in the history
Reverse the bitwise not operations through a double negative.
Add additional checks extra checks.

There is also a ternary being used in the original code that is pointless.
The logic is effectively:
```
  true ?? true : false
```
Get rid of this pointless ternary.
  • Loading branch information
kaladay committed Dec 6, 2022
1 parent 25c2e7f commit 2a1bbd9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/services/userService.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ core.service("UserService", function ($q, StorageService, User, WsApi) {
userEvents.notify('FETCH');

return WsApi.fetch(currentUser.getMapping().instantiate).then(function (res) {
var body = !res.body ? {} : angular.fromJson(res.body);
var credentials = { role: !currentUser.role ? appConfig.anonymousRole : currentUser.role };
var body = !!res && !!res.body ? angular.fromJson(res.body) : {};
var credentials = { role: !!currentUser.role ? currentUser.role : appConfig.anonymousRole };

// Only change credentials when packet structure is valid.
if (!!body.payload && !!body.payload.Credentials) {
if (!!body && !!body.payload && !!body.payload.Credentials) {
delete sessionStorage.role;
credentials = angular.fromJson(res.body).payload.Credentials;
}

currentUser.anonymous = !credentials.role || credentials.role === appConfig.anonymousRole ? true : false;
currentUser.anonymous = !credentials.role || credentials.role === appConfig.anonymousRole;

// Cannot have a token for the anonymous role.
if (currentUser.anonymous) {
Expand Down

0 comments on commit 2a1bbd9

Please sign in to comment.