Skip to content

Instantly share code, notes, and snippets.

@cliffordoravec
Last active September 17, 2018 14:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cliffordoravec/73026ed6471bd213f22c to your computer and use it in GitHub Desktop.
Save cliffordoravec/73026ed6471bd213f22c to your computer and use it in GitHub Desktop.
Using Satellizer with and across subdomains using cookies
/*
Satellizer's storage service can use 'localStorage' and 'sessionStorage' by default.
None of these options work well if you need to use Satellizer with or across subdomains.
(Given, there is the fun iframe and postMessage workaround, but that's really inconvenient.)
Here's a simple approach using cookies for storage, which can be used across subdomains
(since cookies can be used across subdomains, right?).
By default, $http is configured with withCredentials set to false, so the cookies themselves
won't be sent to the server.
Simply add this after you load Satellizer.
Requires ngCookies.
*/
angular.module('satellizer')
.requires.push('ngCookies');
angular.module('satellizer')
.decorator('SatellizerStorage', function($delegate, $cookies) {
var storage = {
get: function(key) {
return $cookies.get(key);
},
set: function(key, value) {
// TODO: Replace '.domain' with your domain!
$cookies.put(key, value, { path: '/', domain: '.domain' });
},
remove: function(key) {
$cookies.remove(key);
}
};
return storage;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment