mike-jumper commented on code in PR #778:
URL: https://github.com/apache/guacamole-client/pull/778#discussion_r1035270551
##########
guacamole/src/main/frontend/src/app/storage/services/localStorageService.js:
##########
@@ -119,25 +140,56 @@ angular.module('storage').provider('localStorageService',
[function localStorage
}
catch (ignore) {}
- // Pull and parse value from internal storage, if present
+ // Pull from internal storage, if present
var data = storedItems[key];
if (data)
- return JSON.parse(data);
+ return data;
// No value defined for given key
return null;
};
+ /**
+ * Retrieves the JSON-serialized value currently stored within localStorage
+ * for the item having the given key. If access to localStorage is not
+ * provided/implemented by the browser, the item is retrieved from
+ * internal, in-memory storage. The retrieved value is automatically
+ * deserialized from JSON prior to being returned.
+ *
+ * @param {String} key
+ * The arbitrary, unique key of the item to retrieve from localStorage.
+ *
+ * @returns {Object}
+ * The value stored within localStorage under the given key,
+ * automatically deserialized from JSON, or null if no such item is
+ * present.
+ */
+ provider.getJsonItem = function getJsonItem(key) {
Review Comment:
Rather than alter the behavior of `getItem()`/`setItem()` and provide new
functions that duplicate the original behavior (thus requiring code using these
functions to be updated), I suggest maintaining the established behavior for
those functions and defining new functions for the new behavior, such as
`getStringItem()`/`setStringItem()`.
Alternatively, the established `getItem()`/`setItem()` should work as
intended regardless of whether the provided data is a full object or just a
string.
##########
guacamole/src/main/frontend/src/app/auth/service/authenticationService.js:
##########
@@ -84,12 +84,7 @@ angular.module('auth').factory('authenticationService',
['$injector',
return cachedResult;
// Return explicit null if no auth data is currently stored
- var data = localStorageService.getItem(AUTH_STORAGE_KEY);
- if (!data)
- return null;
-
- // Update cache and return retrieved auth result
- return (cachedResult = new AuthenticationResult(data));
+ return null;
Review Comment:
As this function will now only return the in-memory cached auth result
provided via `setAuthenticationResult()`, we should note this in the function's
docs, as well as the fact that `setAuthenticationResult()` will be called
automatically upon page load.
##########
guacamole/src/main/frontend/src/app/auth/service/authenticationService.js:
##########
@@ -115,9 +111,10 @@ angular.module('auth').factory('authenticationService',
['$injector',
// Always store in cache
cachedResult = data;
- // Persist result past tab/window closure ONLY if not anonymous
+ // Persist auth token past tab/window closure ONLY if not anonymous
if (data.username !== AuthenticationResult.ANONYMOUS_USERNAME)
- localStorageService.setItem(AUTH_STORAGE_KEY, data);
+ localStorageService.setItem(
+ AUTH_TOKEN_STORAGE_KEY, data.authToken);
Review Comment:
I think we should document that:
* Only the auth token is persisted locally, while the rest of the auth
result is cached only in memory.
* The rest of the authentication result can be obtained by reauthenticating
with the persisted token, which can be retrieved with `getCurrentToken()`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]