Skip to content

Commit

Permalink
fix(pubsub): Update localStorage logic to function when cookies are d…
Browse files Browse the repository at this point in the history
…isabled
  • Loading branch information
stocaaro committed Jan 9, 2023
1 parent 51a1418 commit db0657a
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions packages/pubsub/src/vendor/paho-mqtt.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,39 @@ function onMessageArrived(message) {
// which is used to define the module.
var version = '@VERSION@-@BUILDLEVEL@';

// 2023-01-09: AWS Amplify change to fix the disabled cookies issues:
// https://github.com/eclipse/paho.mqtt.javascript/issues/240

/**
* @private
*/
var localStorage =
global.localStorage ||
(function () {
var data = {};

return {
setItem: function (key, item) {
data[key] = item;
},
getItem: function (key) {
return data[key];
},
removeItem: function (key) {
delete data[key];
},
};
})();
var localStorage;

try {
localStorage = global.localStorage;
} catch (e) {
console.log(e);
} finally {
localStorage =
localStorage ??
(function () {
var data = {};

return {
setItem: function (key, item) {
data[key] = item;
},
getItem: function (key) {
return data[key];
},
removeItem: function (key) {
delete data[key];
},
};
})();
}

// End of AWS Amplify change

/**
* Unique message type identifiers, with associated
Expand Down

0 comments on commit db0657a

Please sign in to comment.