zendesk / cross-storage

Cross domain local storage, with permissions
Apache License 2.0
2.22k stars 180 forks source link

the set item return state null #57

Closed mohamedenab closed 4 years ago

mohamedenab commented 4 years ago

i am trying to redirect my logined user to my sub domain with his credentials so i search about cross local storage and i found this library cross-storage and found this example in angular but when i am trying to set key and then console get that key it return with this

ZoneAwarePromise {__zone_symbol__state: null, __zone_symbol__value: Array(0)}
__zone_symbol__state: null
__zone_symbol__value: []}

here what i done in my component

 storage: any;
 crossDomainItem:any
constructor(private dialog: MatDialog, public authService: AuthService, private router: Router) {
    CrossStorageHub.init([
  {origin: /localhost:4200$/, allow: ['get', 'set', 'del', 'getKeys', 'clear']},
  {origin: /localhost:5000$/, allow: ['get', 'set', 'del', 'getKeys', 'clear']}
]);
this.storage = new CrossStorageClient('http://localhost:4200/home', {
  timeout: 30000000, frameId: 'storageFrame'
});

}

ngOnInit(): void {

this.storage.onConnect().then(() => {
  this.storage.set('cross-domain-item', 'First application cross domain item');
  this.storage.set('lol', 'lol');
});
this.crossDomainItem = this.storage.onConnect().then(() => {
  console.log(this.storage.get('cross-domain-item'));
  console.log(this.storage.get('lol'));
  return this.storage.get('cross-domain-item');
});
}

and loaded the library in angular.json like this

"scripts": [
          "./node_modules/cross-storage/lib/hub.js",
          "./node_modules/cross-storage/lib/client.js"
        ]